Katkat

Implement lexicographically smallest Two Sum

Walmart LabsSoftware Engineer · Technical Screen

Last updated

This question evaluates array manipulation, index-level reasoning, and algorithmic efficiency for locating pair sums under lexicographic tie-breaking, testing attention to ordering constraints and correct index selection.

You are given an unsorted integer array nums and an integer target.

Return the indices [i, j] (0-based) such that i < j and nums[i] + nums[j] == target.

If there are multiple valid pairs, return the pair with the smallest i. If there is still a tie (same i), return the one with the smallest j.

Assume at least one valid pair exists.

Follow-up (discussion only): Explain an efficient approach to find all triplets (i, j, k) with i < j < k such that nums[i] + nums[j] + nums[k] == 0, and you may ignore duplicate triplets (or assume all numbers are distinct).