FastPrepRaise a Number to an Integer Power
Problems/Raise a Number to an Integer Power

Raise a Number to an Integer Power

Adobe logoAdobe● MediumINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: You compute a real number raised to an integer power, which may be negative or very large. A report for a software intern role at Adobe in New Delhi, India (August 2023, no offer) lists a question on coding a function that raises a number to a power. It sits beside a grid word-search task. The report calls the interview hard. It gives only that short label, with no function signature, limits or examples.

We chose these rules. We use the classic form of this task. The base is a real number from -100 to 100 with up to four decimals. The power is any 32-bit integer. Results are no larger than 10^4 in size. Answers are accepted within 10^-5, relative for large results. You may not use a built-in power function. We wrote new examples. The tests cannot see whether you used a built-in power function. The editorial teaches the halving method, and the largest powers time out a loop that goes one step at a time.

Our version is about 80% the same as the reported question.

Given a real number x and an integer n, return x raised to the power n, that is x^n. Do not call a built-in power function.

  • For n > 0, x^n is x multiplied by itself n times.
  • x^0 = 1.
  • For n < 0, x^n = 1 / x^(-n).

Your answer is accepted if it differs from the exact value v by at most 10^-5 * max(1, |v|). So a result smaller than 10^-5 in size may be returned as 0.

Function

power(x: double, n: int) → double

Examples

Example 1

x = 2.0n = 10return = 1024.0

Ten factors of 2: 2 * 2 * ... * 2 = 1024.

Example 2

x = 2.5n = -3return = 0.064

A negative power means one divided by the positive power: 2.5^(-3) = 1 / 2.5^3 = 1 / 15.625 = 0.064.

Example 3

x = -0.5n = -7return = -128.0

(-0.5)^(-7) = 1 / (-0.5)^7 = 1 / (-0.0078125) = -128. The base is negative and the power is odd, so the result is negative.

Constraints

  • -100 <= x <= 100, with at most 4 digits after the decimal point
  • -2^31 <= n <= 2^31 - 1
  • If x is 0, then n > 0
  • The exact value of x^n is between -10^4 and 10^4

More Adobe Phone Screen questions

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
  • Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
  • Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
  • Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
  • Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
  • Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • Multiply Without the Multiplication OperatorMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • IP Address to CIDR BlocksOpenAI · PHONE SCREENOpenAI interview questions
  • Power with Integer ExponentsNVIDIA · PHONE SCREENNVIDIA interview questions
  • Pow(x, n)Bloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Fewest Games to Find the Top Two TeamsSusquehanna International Group (SIG) · PHONE SCREENSusquehanna International Group (SIG) interview questions
  • Count the 1 Bits in a 32-Bit ValueAmazon · PHONE SCREEN
  • Choose the Next Minesweeper ActionRunloop · PHONE SCREEN
  • Checked Recursive SumHeadlands Technologies · PHONE SCREENHeadlands Technologies interview questions
  • Power of Two Without DivisionArm · PHONE SCREEN
  • Powers of Two in a RangeAkuna Capital · PHONE SCREENAkuna Capital interview questions

Interview reports that mention this question

  • Adobe SWE Intern Interviews: 27 Experiences (Part 2 of 4)

Adobe interview experiences

  • Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
  • Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
  • Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
  • Adobe New Grad MTS Interview Questions: 7 Experiences
  • Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)
All Adobe interview questionsSee Adobe hiring insights
Saved
class Solution {
    public double power(double x, int n) {
        // Write your code here.
    }
}
Checking account…