ORIGINAL CODING QUESTION
Modular retry multiplier
Return base^exponent modulo modulus. Define exponent zero as yielding 1 before taking the modulus.
Original exercise · medium. Editorial role relevance does not imply a company has asked this question.
Input and output
base exponent modulus.
Constraints
0 ≤ base ≤ 10000; 0 ≤ exponent ≤ 1000000; 1 ≤ modulus ≤ 10000.
Example 1
Input
3 5 7
Output
5
243 modulo 7 is 5.
Example 2
Input
0 0 9
Output
1
The defined zero exponent gives 1.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
Repeated squaring avoids exponent linear work.
Hint 2
Reduce after every multiplication.
Hint 3
Process the exponent one binary bit at a time.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →