Katkat

Solve unique triplets summing to target

NVIDIASoftware Engineer · Technical Screen

Last updated

Solve unique triplets summing to target evaluates algorithm design, data structures, correctness, complexity, edge cases, and implementation details in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

Implement a function that, given an integer array nums and an integer target T, returns all unique triplets [x, y, z] from nums such that x + y + z = T. Requirements: avoid duplicate triplets (enforce x <= y <= z within each triplet), return results in lexicographic order, and aim for O(n^ 2) time using sorting and a two-pointer strategy with O(

  1. extra space beyond the output. Discuss edge cases (duplicates, all zeros, no solution, mixed signs, large n) and provide a concise set of test cases. Analyze time and space complexity.