Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Exponentiation Power Function
00:00
5 left

Exponentiation Power Function

EasyPython

Problem

AQR research calculations may repeatedly evaluate integer powers for signal transformations. Implement exponentiation without using Python's built-in power operators or libraries.

Given a numeric base x and an integer exponent y, return x raised to the power y. In this problem, ^ means exponentiation, not bitwise XOR.

Your solution should use exponentiation by squaring rather than multiplying by x once for every unit of the exponent. Negative exponents must return the reciprocal power.

Formal Specification

  • Input: x, a nonzero integer or floating-point number when y < 0, and y, an integer.
  • Output: The numeric value x^y. Returning an integer for integral positive powers and a floating-point value for negative powers is acceptable.
  • Do not use **, pow, or equivalent library functions.

Constraints

  • -100 <= x <= 100
  • x != 0 when y < 0
  • -10^9 <= y <= 10^9
  • 0^0 is defined as 1
  • Do not use **, pow, or equivalent library functions

Function Signature

def power(x, y):
Interviewer

Your question is Exponentiation Power Function. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.