Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Efficient String and Target Sum

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

Your question is Efficient String and Target Sum. 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

An Amazon Robotics fulfillment station receives item weights as decimal strings. Given an array of weight strings and an integer target weight, return the indices of two distinct entries whose numeric values sum to the target.

Parse each weight string, including an optional leading + or -, without relying on floating-point arithmetic. Return the pair of indices in ascending order. Each valid input contains exactly one solution.

Formal Specification

Implement find_target_pair(weights, target).

  • Input: weights, an array of strings representing integers, and target, an integer.
  • Output: An array [i, j], where i < j and the parsed values satisfy weights[i] + weights[j] == target.
  • Do not reuse the same array element.

Constraints

  • 2 <= len(weights) <= 10^5
  • Each string contains an optional sign followed by at least one decimal digit
  • 1 <= len(weight_string) <= 20
  • Parsed values fit within signed 64-bit integer range
  • -10^18 <= target <= 10^18
  • Exactly one valid pair exists

Function Signature

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