Interview Questions

Implement pow(a,b) without multiplication or division

This is one type of very common interview question that is usually asked, where your goal is to implement some built-in language function, such as exponentiation, division, hash tables, etc. In this challenge we need to implement exponentiation, or raising **a** to some power of **b** which is usually written pow(a, b). In this variation of the challenge, we also need to implement a solution without using the multiplication or division operations, only addition and subtraction are allowed.
## Example of how pow(a, b) works

You need to be a premium member to see the rest of this question and code.

With our large collection of challengs, tutorials, and solutions, we make it easy for you to become a better coder, prepare for interviews, and learn new skills from more experienced coders.

- 200+ Coding Challenges
- Mock Interview Questions
- 500,000+ Code Solutions
- Algorithm Tutorials
- Interview Prep Courses

mrdaniel
published this on 11/25/15 **|**

0

Using recursion and closure

function pow(num, e) { let exponent; let value = num; addup(); function addup(outernum = num, iterate = 1) { if (iterate == e) { return; } for (let counter = 1; counter < num; counter++) { value += outernum; } exponent = value; return addup(value, iterate + 1); } return exponent; }

jaitthomas

commented on 02/21/17

Login to submit a comment