Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

199. Pow(x, n)

MediumDay 59 of 60Bit Manipulation & Math

Implement myPow(x, n), which returns x raised to the integer power n. The exponent can be negative, and it can be as large as about two billion in absolute value, so multiplying x by itself n times is too slow.

Example 1
Input: x = 2.0, n = 10
Output: 1024.0
Example 2
Input: x = 2.0, n = -2
Output: 0.25
2^-2 = 1 / 2^2 = 1 / 4
Constraints
  • -100.0 < x < 100.0
  • -2^31 <= n <= 2^31 - 1
  • x is not zero when n is negative
  • Answers are compared with a small tolerance
Hints
Frequently asked at: Meta, Amazon, Google, LinkedIn
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min