A bundle builder suggests pairs of prices that add up to target. It should list each pair of values once, even if the same prices appear many times in nums.
Write uniquePairs(nums, target) that returns every distinct pair [a, b] with a <= b and a + b === target, where a and b come from two different indexes. Sort the pairs by a, smallest first.
Input: nums = [1,5,3,3,7,5,-1], target = 6 Output: [[-1,7],[1,5],[3,3]]
Each pair of values is listed once. [3, 3] works because 3 appears twice.
Input: nums = [3,4], target = 6 Output: []
3 + 3 would need two different 3s.
0 <= nums.length <= 10^5-10^9 <= nums[i], target <= 10^9Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #32 Distinct Price Pairs. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.