Code Room
CodingHardcod-g186
Subject Modular arithmeticLevel Senior–Staff~35 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

You are given two equal-length lists, remainders and moduli, describing a system of congruences x ≡ remainders[i] (mod moduli[i]) for each i. The moduli are positive but NOT necessarily pairwise coprime. Return the smallest non-negative x satisfying all congruences, or -1 if the system is inconsistent. For example, x ≡ 2 (mod 3), x ≡ 3 (mod 5), x ≡ 2 (mod 7) yields 23. All values fit in 64-bit integers.

Implement
crt(remainders: list[int], moduli: list[int]) → int
Examples
in[[2,3,2],[3,5,7]]out23
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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.