As reported: Walmart SWE III onsite hiring drive, round 1 DS/Algo (Bangalore, Mar 2025), three questions instead of the usual two: 3Sum, the index of the next smaller element to the right, and Largest Rectangle in Histogram.
Given an integer array nums, return all distinct triplets [a, b, c] of values at three different indices with a + b + c = 0.
This is LeetCode 15 — 3Sum.
Example
[-1,0,1,2,-1,-4] -> [[-1,-1,2],[-1,0,1]]
[0,1,1] -> []
[0,0,0] -> [[0,0,0]]
Constraints: 3 ≤ nums.length ≤ 3000; -10^5 ≤ nums[i] ≤ 10^5.
Code runner format: one line with nums. Implement threeSum(nums); any order of the triplets (and within one) is accepted.