Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

3Sum Coding Problem

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

Your question is 3Sum Coding Problem. 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

Cloudflare Workers can process collections of numeric request or event attributes at the edge. Given an integer array nums, return every unique triplet of values whose sum is zero.

Formal Specification

Implement three_sum(nums). The input is a list of integers. Return a list of lists, where each inner list contains three integers satisfying a + b + c == 0. Do not return duplicate triplets. The order of the triplets and the values within each triplet may be considered arbitrary, but sorting both provides deterministic output.

Constraints

  • 3 <= nums.length <= 3000
  • -10^5 <= nums[i] <= 10^5
  • Each triplet must use three distinct array positions
  • Duplicate value combinations must appear only once

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