Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Find Unique Triplets That Sum to Zero

MediumPython00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the Python screen.

The question is on your right: Find Unique Triplets That Sum to Zero. Read through the requirements first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

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