Modular exponentiation
Compute (base ^ exp) mod m without ever materializing the full power, which can be astronomically large. You are given three non-negative integers base, exp, and m (1 <= m <= 1e9, 0 <= base, exp <= 1e9). Return base raised to exp, modulo m. Note that any value modulo 1 is 0, and base^0 is 1 (taken mod m).
Implement
mod_pow(base: int, exp: int, m: int) → intExamples
in
[2,10,1000]out24What 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 20 min
solution.py
InputExpectedGot
[2,10,1000]24not run yetsample