Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Find Unique Triplets That Sum to Zero

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Find Unique Triplets That Sum to Zero. Start with the requirements on the right.

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.

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):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output