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
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
Target From Number String
00:00
5 left

Target From Number String

HardPython

Problem

Veeva Vault configuration data can encode numeric expressions as a single digit string. Given a string of digits and a target integer, split the string into exactly three nonempty numbers without changing digit order, insert one operator between adjacent numbers, and return an equation that evaluates to the target.

Allowed operators are +, -, and *. Multiplication follows normal arithmetic precedence. A number may not contain leading zeroes unless it is exactly 0. Return any valid equation as a string in the form a<op1>b<op2>c=target. Return None if no valid equation exists. The function should not print directly, which makes the result easier to test.

Formal Specification

  • Input: digits, a string containing only characters from 0 through 9, and target, an integer.
  • Output: A valid equation string, or None when no solution exists.
  • The three numbers must be contiguous, nonempty substrings whose concatenation equals digits.

Constraints

  • 3 <= len(digits) <= 300
  • digits contains only characters from 0 through 9
  • -10^18 <= target <= 10^18
  • Numbers may not have leading zeroes unless the number is exactly 0
  • The three numbers must be nonempty contiguous substrings
  • Return any valid equation, or None if no equation exists

Function Signature

def build_expression(digits, target):
Interviewer

Your question is Target From Number String. 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.