ribbon logo
ribbon contest type Free Academy Experience

Preparing for tech interviews?
Learn from the best instructors in the field.

Try Academy for FREE!

Implement Power Function

Implement pow(x, n) % d.

In other words, given x, n and d,

find (xn % d)

Note that remainders on division cannot be negative.
In other words, make sure the answer you return is non negative.

Input : x = 2, n = 3, d = 3
Output : 2

2^3 % 3 = 8 % 3 = 2.
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Implement Power Function on Interview Code Editor
  • Hint 1
  • Solution Approach
  • Complete Solution
Asked In:


Click here to start solving coding interview questions