As reported: Walmart SDE-3 hiring drive, round 1 DSA (May 2025): Two Sum in two versions — one with unique values / pairs and one with repeated values — followed by a connected-components question.
Given an array nums and an integer target, return the indices of the two numbers that add up to target. Each input has exactly one solution and the same element may not be used twice. Values may repeat.
This is LeetCode 1 — Two Sum.
Example
nums = [2,7,11,15], target = 9 -> [0,1]
nums = [3,2,4], target = 6 -> [1,2]
nums = [3,3], target = 6 -> [0,1]
Constraints: 2 ≤ nums.length ≤ 10^4; -10^9 ≤ nums[i], target ≤ 10^9; exactly one valid answer.
Code runner format: one JSON value per line: nums, then target. Implement twoSum(nums, target); any order of the two indices is accepted.