Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Triplets Sum to Zero
00:00
5 left

Triplets Sum to Zero

MediumPython

Problem

TeachMint may need to group three numeric signals whose combined adjustment is zero. Given an integer array nums, find every unique triplet of distinct array elements whose values sum to 0.

Return the triplets as a list of lists. Each triplet must be sorted in nondecreasing order, and the complete result must not contain duplicate triplets. The result may be returned in lexicographic order. You may reorder nums during processing.

Formal Specification

  • Input: nums, a list of integers.
  • Output: A list of unique lists, where each inner list contains three integers and sums to 0.
  • Each array position can be used at most once for a triplet.

Constraints

  • 3 <= nums.length <= 3000
  • -10^5 <= nums[i] <= 10^5
  • Each triplet must use three different indices
  • Duplicate triplets must not be returned

Function Signature

def three_sum(nums):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

You need to log in / sign up to run or submit.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.