Modular inverse extended euclidean
Compute the modular multiplicative inverse of a modulo m, i.e. the integer x in [0, m) with (a * x) mod m == 1, or return -1 if no inverse exists (when gcd(a, m) != 1). Here m may NOT be prime, so Fermat's little theorem does not apply; use the extended Euclidean algorithm. By convention return 0 when m == 1.
Implement
mod_inverse(a: int, m: int) → intExamples
in
[3,11]out4What 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 25 min
solution.py
InputExpectedGot
[3,11]4not run yetsample