Free 30-minute trial

500+ reviews from engineers

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.

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²).

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

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