Extended Euclidean algorithm

Write codeHard30 min

Your task

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 ax + by = 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).

Examples

ext_gcd(a: int, b: int) -> list[int]
Example 1
Inputext_gcd(240, 46)
Output[2, -9, 47]