Power with Integer Exponents
Updated
Problem statement
Implement myPow(x, n), which returns the real number x raised to the signed 32-bit integer exponent n.
Your implementation must handle zero and negative exponents and must not overflow when negating the minimum 32-bit integer.
Function
myPow(x: double, n: int) → doubleExamples
Example 1
x = 2.0n = 10return = 1024.0Multiplying ten factors of 2 gives 1024.
Example 2
x = 2.0n = -2return = 0.25A negative exponent uses the reciprocal: 2^-2 = 1 / 4.
Constraints
nis any signed 32-bit integer.- If
xis0, thennis positive. - Answers are compared with relative or absolute tolerance
10^-9.
More LinkedIn Onsite Interview questions
- Allocate Mailboxes with Squared DistanceONSITE INTERVIEW · Seen Nov 2026
- Find Leaves of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
- Max Points on a LineONSITE INTERVIEW · Seen Nov 2026
- Explore an Unknown Grid and Find a PathONSITE INTERVIEW · Seen Nov 2026
- Fire Station Response BillONSITE INTERVIEW · Seen Nov 2026
- Roll a Weighted DieONSITE INTERVIEW · Seen Oct 2026
- Longest Binary Subarray With at Most K OnesONSITE INTERVIEW · Seen Oct 2026
- Kth Closest Element in a BSTONSITE INTERVIEW · Seen Oct 2026
- Longest Binary Window with at Most K OnesONSITE INTERVIEW · Seen Oct 2026
- LRU Cache OperationsONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Path Between Two Nodes of a Fibonacci TreeDatabricks · PHONE SCREEN · ONSITE INTERVIEWDatabricks interview questions
- Every Result of Grouping an ExpressionC3.ai · ONSITE INTERVIEWC3.ai interview questions
- Pow(x, n)Bloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Integer Power Without a Library CallExpedia · ONSITE INTERVIEWExpedia interview questions
- Fibonacci NumberMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Decision Tree Classifier from ScratchZillow · ONSITE INTERVIEWZillow interview questions
- Josephus SurvivorApple · ONSITE INTERVIEWApple interview questions
- N-th Fibonacci NumberBank of America · ONSITE INTERVIEWBank of America interview questions
- Integer to English Words: Up to 20 DigitsPeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
- Fibonacci with Input ValidationMorgan Stanley · ONSITE INTERVIEWMorgan Stanley interview questions