Chinese remainder theorem
Given pairwise-coprime moduli and corresponding remainders, find the smallest non-negative x satisfying x = remainders[i] (mod moduli[i]) for all i, using the Chinese Remainder Theorem. Return a two-element list [x, M] where M is the product of all moduli and x is the unique solution in [0, M). Constraints: 1 to 10 congruences, each modulus 1 <= moduli[i] <= 1000, moduli are pairwise coprime, 0 <= remainders[i] < moduli[i].
Implement
crt(remainders: list[int], moduli: list[int]) → list[int]Examples
in
[[2,3,2],[3,5,7]]out[23,105]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 35 min
solution.py
InputExpectedGot
[[2,3,2],[3,5,7]][23,105]not run yetsample