Interview Questions

  • View all interview questions
  • blank
  • 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.

    Become a Premium Member

    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.

    “Also important to try coding in nonstructured or semistructured environments to see if you like it. Coderbyte really helped me.“ ― Jeff Ruder
    • 200+ Coding Challenges
    • Mock Interview Questions
    • 500,000+ Code Solutions
    • Algorithm Tutorials
    • Interview Prep Courses
    mrdaniel published this on 11/25/15 | math, Microsoft
    Comments
  • +
  • 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;
    }
    
    Login to submit a comment