Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Find Unique Triplets That Sum to Zero
00:00
5 left

Find Unique Triplets That Sum to Zero

MediumPython

Problem

Given an integer array nums, return all the unique triplets [nums[i], nums[j], nums[k]] such that i, j, and k are distinct indices and nums[i] + nums[j] + nums[k] == 0.

The solution must avoid duplicate triplets in the output.

Constraints

  • 0 <= nums.length <= 3000
  • -10^5 <= nums[i] <= 10^5

Function Signature

def three_sum(nums):
Interviewer

Your question is Find Unique Triplets That Sum to Zero. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.