Code Room
CodingMediumcod-g394
Subject Modular arithmeticLevel Mid–Senior~20 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

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.