Two Sum Is Not About Numbers #1
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Title: Two Sum Is Not About Numbers
Description:
You are given a list of records. Each record contains:
Your task is to find whether there exists a pair of records whose values sum to a given target.
Return the identifiers of any such pair.
If no such pair exists, return an empty result.
Notes:
Function signature example:
findPair(records, target) -> pair of identifiers or empty result
Example 1:
Input:
records = [
{ id: "A", value: 2 },
{ id: "B", value: 7 },
{ id: "C", value: 11 },
{ id: "D", value: 15 }
]
target = 9
Output:
["A", "B"]
Explanation:
2 + 7 = 9
Example 2:
Input:
records = [
{ id: "X", value: 3 },
{ id: "Y", value: 2 },
{ id: "Z", value: 4 }
]
target = 6
Output:
["Y", "Z"]
Example 3:
Input:
records = [
{ id: "K", value: 3 },
{ id: "L", value: 3 }
]
target = 6
Output:
["K", "L"]
Constraints:
Follow-up:
Can you solve it in better than O(n^2) time?
03 — Two Sum Is Not About Numbersto 03 Two Sum Is Not About Numbers03 Two Sum Is Not About Numbersto Two Sum Is Not About NumbersAnother variant of this task:
Given an array of records and an integer target, return the identifiers of the two records such that their values add up to target.
You may assume that each input has at most one solution, and you may not use the same record twice.
You can return the answer in any order.
Internal note:
This task is intentionally framed as a classic pair-sum problem, but the goal of the analysis is to show that in real engineering the difficulty is usually not the arithmetic itself, but data interpretation, context, constraints, and system behavior.