Code RoomModular exponentiation
MediumPrep Room Coding #963

Modular exponentiation

CodingAlgorithms & data structuresMid–Senior~20 min

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) → int
Examples
in[2,10,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 20 min
InputExpectedGot
[2,10,1000]24not run yetsample