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
Two Sum and Variants
00:00
5 left

Two Sum and Variants

HardPython

Problem

A Delivery Hero India client processes compact arrays and encoded values. Implement one function that performs three independent analyses efficiently:

  1. Two Sum: Return the indices of two distinct elements in nums whose values add to target. Return the first pair found while scanning from left to right, or [] if no pair exists.
  2. Binary Sum: Add two non-negative binary strings binary_a and binary_b without converting either full string to an integer. Return the canonical binary result without leading zeroes, except that zero is represented as "0".
  3. First Duplicate: Scan values from left to right and return the first value whose second occurrence appears earliest. Return None if every value is unique.

Return a dictionary with keys two_sum, binary_sum, and first_duplicate.

Formal Specification

nums is a list of integers, target is an integer, binary_a and binary_b are binary strings, and values is a list of hashable values. The result is a dictionary containing a list of indices, a binary string, and either a value or None.

Constraints

  • 0 <= len(nums), len(values) <= 10^5
  • -10^9 <= nums[i], target <= 10^9
  • Each binary string contains only '0' and '1'
  • The length of each binary string is at most 10^5
  • Values in values are hashable
  • Do not convert binary strings to integers

Function Signature

def analyze_inputs(nums, target, binary_a, binary_b, values):
Interviewer

Your question is Two Sum and Variants. 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.