DIY: Pow(x, n)
Solve the interview question "Pow(x, n)" in this lesson.
We'll cover the following
Problem statement
For this problem, you are given an integer base
and power
value. You have to implement the pow()
function, which will raise the base
to a specified power and return its value.
Assume the following constraints:
- -100 <
base
< 100 - - <=
power
<= -1 - - <= <= , where
x
is thebase
and n is thepower
.
Input
The function will take two inputs: base
and power
. Here is an example of the inputs:
base = 2
power = 4
Output
The function returns the base
raised to a specified power
. The following is the output of the inputs shown above:
16
Coding exercise
You need to implement the pow(base, power)
function in the skeleton code given below.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.