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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.