Power with Integer Exponents
Updated
Problem statement
Given a real number x and integer n, implement myPow(x, n) to return x^n without a built-in power function.
For this exercise, a zero exponent returns 1 and a negative exponent returns the reciprocal of the positive power. When x = 0, n is positive.
Function
myPow(x: double, n: int) → doubleExamples
Example 1
x = 3.0n = 4return = 81.0Four factors of three give 81.
Example 2
x = 4.0n = -2return = 0.0625The reciprocal of sixteen is 0.0625.
Example 3
x = 2.5n = 0return = 1.0Any nonzero base to exponent zero is one.
Constraints
-100 < x < 100;xis finite.-2^31 <= n <= 2^31 - 1.- The mathematical result is between
-10^4and10^4and representable as a finite double; very small magnitudes may underflow to zero. - Outputs are compared using absolute or relative tolerance
10^-9.
More NVIDIA Phone Screen questions
- Network Layer Execution OrderPHONE SCREEN · Seen Nov 2026
- Paged KV Cache AccessPHONE SCREEN · Seen Nov 2026
- Sliding Window Attention over a KV CachePHONE SCREEN · Seen Nov 2026
- Summarize Server Healthcheck LogsPHONE SCREEN · Seen Oct 2026
- Hash Partition OffsetsPHONE SCREEN · Seen Oct 2026
- Filter Paginated Medical RecordsPHONE SCREEN · Seen Oct 2026
- Least Frequently Used CachePHONE SCREEN · Seen Oct 2026
- Parallel String Counts with a Custom Hash TablePHONE SCREEN · Seen Oct 2026
- Simulate a Reference-Counted Smart PointerPHONE SCREEN · Seen Aug 2026
- Streaming Top-K Frequent ElementsPHONE SCREEN · Seen Aug 2026
Similar questions at other companies
- Path Between Two Nodes of a Fibonacci TreeDatabricks · PHONE SCREEN · ONSITE INTERVIEWDatabricks interview questions
- Raise a Number to an Integer PowerAdobe · PHONE SCREENAdobe interview questions
- Pow(x, n)Bloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Checked Recursive SumHeadlands Technologies · PHONE SCREENHeadlands Technologies interview questions
- Odd Numbers Up and BackNutanix · PHONE SCREENNutanix interview questions
- FactorialZillow · PHONE SCREEN · ONSITE INTERVIEWZillow interview questions
- Factorial Without MultiplicationWayve · PHONE SCREEN
- Power with Integer ExponentsLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Reach a Given NumberHyperVerge · OA
- Is PossibleGoldman Sachs · OAGoldman Sachs interview questions