Medium · Two pointers · spoken drill

Free AI LeetCode Communication Coach — 3Sum

Sort, fix i, then two pointers for the pair that sums to −nums[i]. Deduplicate out loud.

The problem

Given an integer array nums, return all unique triplets that sum to zero.

Example: nums = [-1,0,1,2,-1,-4] → [[-1,-1,2],[-1,0,1]]

Sort + two pointers + duplicate skip.

nums.sort()
res = []
for i in range(len(nums)):
    if i and nums[i] == nums[i-1]:
        continue
    left, right = i + 1, len(nums) - 1
    while left < right:
        total = nums[i] + nums[left] + nums[right]
        if total == 0:
            res.append([nums[i], nums[left], nums[right]])
            left += 1
            while left < right and nums[left] == nums[left-1]:
                left += 1
        elif total < 0:
            left += 1
        else:
            right -= 1
return res

How to explain it

  1. 1. Restate

    Say the problem in your own words.

    One or two sentences. Show you understood the input, the output, and the goal — not that you memorised the prompt.

  2. 2. Approach

    Name the method before you code.

    Brute force first if you need it, then the structure you will use: hash map, two pointers, stack, binary search.

  3. 3. Example

    Walk one concrete input.

    Pick small numbers. Say what you store, what you compare, and what you return. Interviewers follow an example more easily than abstract talk.

  4. 4. Time and space

    One sentence each.

    After the example, before you claim you are done. “Time is O(n) because we scan once. Space is O(n) for the map.”

  5. 5. Edge cases

    Name at least one unusual input.

    Empty input, duplicates, already sorted, overflow. Invite a follow-up: “I would also check …”

  • “I sort, fix one index, then two pointers.”
  • “I skip duplicates on i, left, and right.”

Practise out loud

3 free scored runs left this hour.

Problem · Medium

Given an integer array nums, return all unique triplets that sum to zero.

Example: nums = [-1,0,1,2,-1,-4] → [[-1,-1,2],[-1,0,1]]

  1. 1Restate — Say the problem in your own words.
  2. 2Approach — Name the method before you code.
  3. 3Example — Walk one concrete input.
  4. 4Time and space — One sentence each.
  5. 5Edge cases — Name at least one unusual input.

Hit record. Short countdown, then 60–90 seconds. We score the five-step script — never pronunciation.

Recording needs Chrome or Edge. You can still type below.

Model spoken script (~75s)

  1. 1. Restate

    I need every unique triplet that adds to zero.

  2. 2. Approach

    I sort the array. For each index i I run two pointers on the rest looking for a pair that sums to minus nums[i]. I skip duplicates.

  3. 3. Example

    On −1,0,1,2,−1,−4 after sort, when i is −1 I find −1,2 and 0,1. I skip the next −1 so I do not repeat.

  4. 4. Time and space

    Time is O(n²). Extra space is O(1) besides the output.

  5. 5. Edge cases

    I would check arrays shorter than three and the all-zeros case.

How to explain 3Sum out loud, step by step

In one sentence: You have to list every distinct group of three numbers from the array whose total is exactly zero, without repeating the same group twice.

What to say, in order

  1. “The output is a list of unique triplets with a sum of zero, so duplicate handling is half of this problem.”
  2. “First I sort the array. Sorting lets me use two pointers and makes duplicates sit next to each other.”
  3. “Then I fix one number at index i. For the rest of the array I need a pair that sums to minus that number.”
  4. “I put a left pointer just after i and a right pointer at the end. If the sum is too small, I move left forward; if it's too big, I move right back.”
  5. “When I find a zero sum, I record the triplet, then move both pointers and skip over equal values so I don't record the same triplet again.”
  6. “I also skip i when it has the same value as the previous i. And once the fixed number is positive, I can stop, because three positives can't sum to zero.”

Key English phrases for 3Sum

fix one element
— choose the first number of the triplet in the outer loop
reduce it to Two Sum
— the inner problem is a pair sum on a sorted range
skip duplicates
— advance past equal neighbours after sorting
too small / too big
— the rule for which pointer to move
early exit
— stopping when the fixed number becomes positive

How to say the time and space complexity

“Time is O(n squared): sorting is O(n log n), and for each of the n fixed numbers the two-pointer scan is O(n). Space is O(1) extra apart from the output, though the sort itself may use some extra memory depending on the language.”

Say 'n squared dominates n log n' so the interviewer hears why the sort doesn't change the final bound.

Communication mistakes on 3Sum

  • Mistake: Saying 'I'll use a set to remove duplicate triplets' as the main plan. Instead: Say 'Because the array is sorted, I skip equal neighbours, so duplicates never get added.'
  • Mistake: Saying 'three pointers' without explaining which one is fixed. Instead: Say 'one fixed index in the outer loop, and two moving pointers inside it.'
  • Mistake: Giving O(n log n) as the final time because you mentioned sorting last. Instead: Finish with the dominant term: 'Overall it's O(n squared).'
  • Mistake: Mumbling the pointer rule. Instead: Use one clear sentence: 'If the sum is below zero I move left; above zero I move right.'

Likely follow-up questions

  • Interviewer: “How would you find the triplet whose sum is closest to a target?”

    You: “Same skeleton: sort, fix i, two pointers. Instead of checking for zero, I track the sum with the smallest absolute difference from the target and move the pointers the same way. Still O(n squared).”

  • Interviewer: “How does this extend to four numbers?”

    You: “I add one more outer loop: fix two numbers, then run two pointers on the rest. That gives O(n cubed), with the same duplicate skipping at every level.”

Common mistakes when explaining 3Sum

  • Forgetting to say how you skip duplicates.
  • Claiming O(n) when the two-pointer loop is O(n²).

Other problems

Browse full catalogue

FAQ

Questions

Sort, fix i, two pointers, skip duplicates, O(n²).

Sorting enables the two-pointer scan and places equal values next to each other, so you can skip duplicates without an extra set.

O(n squared): an outer loop over n fixed numbers with an O(n) two-pointer scan inside. The O(n log n) sort is dominated.

More questions? Email us at contact@mocklyenglish.com.

Course: How to explain a LeetCode solution · Think out loud · Explain code out loud

For bots & AI agents

Machine-readable versions of this page and Mockly English. Mockly English, the live-class and Interview English arm of Speak Tech English, gives non-native engineers live 1:1 classes with real human tutors in tech interview and business English, plus a free iPhone app, free practice Mini Apps and a self-paced course. Fetch these instead of parsing this page.

This Mini App (.md)llms.txtllms-full.txtai.txtFact sheetFull catalog (.md)Endpoint indexAI catalogAgent skillsMCP serverMCP server cardAgent sign-in (auth.md)Sitemaprobots.txtUse Mockly in ChatGPT & ClaudeiPhone appDeveloper docsSpeak Tech English