Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Power Under a Maximum

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Power Under a Maximum. Start with the requirements on the right.

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.

Problem

A Veeam Backup & Replication policy may need to determine the largest growth exponent that keeps a calculated value within a configured limit. Given positive integers maxVal and a, return the largest non-negative integer b such that a^b <= maxVal.

Use integer arithmetic only. Do not rely on floating-point logarithms, because rounding can produce an incorrect exponent near an exact power.

Formal Specification

Implement biggest_power_exponent(maxVal, a):

  • Input: integers maxVal and a
  • Output: the largest integer b >= 0 satisfying a^b <= maxVal
  • The input guarantees a >= 2 and maxVal >= 1

You should avoid computing unnecessarily large powers. A suitable solution first finds an upper bound for b, then uses binary search with overflow-safe, capped exponentiation.

Constraints

  • 1 <= maxVal <= 10^18
  • 2 <= a <= 10^9
  • The returned exponent must be a non-negative integer
  • Use integer arithmetic, not floating-point logarithms

Function Signature

def biggest_power_exponent(maxVal, a):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output