Code RoomModular exponentiation large exponent
MediumPrep Room Coding #1193

Modular exponentiation large exponent

CodingAlgorithms & data structuresMid–Senior~25 min

Compute a^b mod m using fast (binary) exponentiation, where b is given as a list of decimal digits of a potentially very large exponent (most-significant digit first). Return (a^b) mod m. Constraints: 0 <= a < 10^9, m >= 1, and the digit list has length 1..50 with each entry in 0..9 (no leading-zero requirement; the list [0] means exponent 0).

Implement
pow_big_exp(a: int, digits: list[int], m: int) → int
Examples
in[2,[1,0],1000]out24
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 25 min
InputExpectedGot
[2,[1,0],1000]24not run yetsample