Code RoomExtended Euclidean algorithm
HardPrep Room Coding #1205

Extended Euclidean algorithm

CodingAlgorithms & data structuresSenior–Staff~30 min

Implement the extended Euclidean algorithm: given non-negative integers a and b (not both zero, each <= 10^9), return [g, x, y] where g = gcd(a, b) and x, y are Bezout coefficients satisfying a*x + b*y = g. Among the infinitely many (x, y), return the canonical pair produced by the standard recursive/iterative extended-Euclid (the one with the smallest |x| that the textbook algorithm yields).

Implement
ext_gcd(a: int, b: int) → list[int]
Examples
in[240,46]out[2,-9,47]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 30 min
InputExpectedGot
[240,46][2,-9,47]not run yetsample