Easy · spoken drill

How to Explain Valid Parentheses in English

Valid Parentheses is a stack story. Say you push opening brackets, pop when a closer matches, and fail if the stack is empty too soon or not empty at the end.

The problem

Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. Brackets must close in the correct order, and every closer must match the same type of opener.

Narrate a stack. Interviewers want to hear “push opener, pop on match,” not a regex.

pairs = {")": "(", "]": "[", "}": "{"}
stack = []
for ch in s:
    if ch in "([{":
        stack.append(ch)
    elif not stack or stack.pop() != pairs[ch]:
        return False
return not stack

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 will use a stack.”
  • “I push openers and pop when a closer matches.”
  • “If I pop from an empty stack, it is invalid.”
  • “At the end the stack must be empty.”

Practise out loud

Record 60–90 seconds. Play it back, then get a scorecard. Audio is scored and discarded.

This browser cannot record audio. Type your explanation below.

0:00 / 1:30

Model spoken script

I will restate the problem. I have a string of brackets, and I need to say whether every closer matches the right opener in the right order. I will use a stack. I push opening brackets. When I see a closer, I pop and check it matches. If the stack is empty when I try to pop, the string is invalid. For example, '{[]}' — I push curly, push square, then the square closer matches, then the curly closer matches, and the stack is empty, so it is valid. Time is O(n). Space is O(n) in the worst case, all openers. I would also check an empty string — that is valid — and a leftover opener at the end, like '('.

Other problems

FAQ

Questions

Name a stack, push openers, pop on a matching closer, and require an empty stack at the end. Walk '{[]}', then mention the leftover-opener case.

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

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

Quick answer

Explain a LeetCode solution in English with a fixed order: restate, name the approach, walk an example, state time and space, then name an edge case. Record 60–90 seconds and get a scorecard on that structure — not on your accent.

Free 30-minute trial

Take a mock interview

Get feedback on your answers and your English from certified coaches.

Sophie

5.0 · 159 reviews

Tom

5.0 · 156 reviews

No credit card needed