Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Three 2s Maximum Value
00:00
5 left

Three 2s Maximum Value

HardPython

Problem

For a Searce coding screen, determine the largest integer that can be formed using exactly three occurrences of the number 2. You may combine subexpressions with binary operators and apply factorial as a unary operator.

Implement highest_three_twos(max_ops) using at most max_ops mathematical operations.

Allowed operations are:

  • Binary: +, -, *, exact integer division /, and exponentiation **
  • Unary: factorial !
  • Parentheses may be used freely.

Every intermediate result must be an integer with absolute value at most 10^8. Factorial is defined only for integers from 0 through 8. Division is valid only when the divisor is nonzero and the result is integral. Exponents must be nonnegative integers from 0 through 30.

Return the maximum value among all valid expressions. If an expression uses fewer than max_ops operations, it is still valid.

Constraints

  • 2 <= max_ops <= 8
  • Exactly three literal 2 values must be used
  • Intermediate values have absolute value at most 10^8
  • Factorial inputs must be integers from 0 through 8
  • Exponents must be integers from 0 through 30
  • Division must be exact and cannot use zero as the divisor

Function Signature

def highest_three_twos(max_ops):
Interviewer

Your question is Three 2s Maximum Value. 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
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.