Technical Interviews5 min read

The Coding Interview Script: How to Think Out Loud Using Patterns

Learn a concrete framework to articulate your thought process in coding interviews by using common algorithm patterns as a script to go from brute-force

Sasha Romanov

Engineering Editor

Interviewers don't just want the right code; they want to see how you get there. But the common advice to 'think out loud' is vague and often leads to a rambling, unstructured monologue. A better approach is to use a script—a framework for communication grounded in the very patterns you use to solve the problem. This turns your thought process into a clear, compelling narrative.

This guide provides that script. By consciously identifying a brute-force approach, naming a specific algorithmic pattern for optimization (like Sliding Window or Two Pointers), and then walking the interviewer through the logic, you demonstrate structured problem-solving. You prove you can not only find the optimal solution but also communicate your reasoning effectively, a key metric in technical interviews at companies like Google.

Why 'Just Think Out Loud' Is Bad Advice

A raw stream of consciousness is often confusing for the listener. When an interviewer says, "talk me through your thought process," they aren't asking for a chaotic brain dump. They are evaluating a specific set of skills that go beyond just coding.

Your communication should demonstrate:

  • **Problem Decomposition:** Can you break an ambiguous problem into smaller, concrete steps?
  • **Solution Exploration:** Do you consider multiple approaches, starting with a simple brute-force method before optimizing?
  • **Trade-off Analysis:** Can you clearly state the time and space complexity of your solutions and explain why one is better than another?
  • **Collaboration:** Is your explanation clear enough for the interviewer to follow, ask questions, and offer hints if you get stuck?

A random monologue achieves none of these. A structured script does.

The Pattern-Driven Script: A 4-Step Framework

Instead of improvising, follow this repeatable framework. It uses common data structure and algorithm patterns as signposts to guide your conversation from the problem statement to the optimal code.

  1. **Clarify and State the Brute-Force:** First, repeat the problem in your own words to confirm your understanding. Ask about constraints and edge cases (e.g., 'Are the numbers sorted? Can the array be empty?'). Then, state the most obvious, even if inefficient, solution. Example: 'My first instinct is to use nested loops to check every possible pair, which would be O(n^2).'
  2. **Identify the Bottleneck & Name the Pattern:** Articulate *why* the brute-force approach is slow. Pinpoint the repeated work. Then, explicitly name the algorithmic pattern that can fix it. Example: 'The bottleneck is re-scanning the array for each element. Since the array is sorted, I can use the **Two Pointers** pattern to solve this in O(n) time.'
  3. **Explain the Optimal Logic:** Before writing code, describe how the pattern works for this specific problem. Explain the mechanics. Example: 'I'll place one pointer at the beginning and one at the end. I'll sum their values. If the sum is too small, I'll move the left pointer forward. If it's too large, I'll move the right pointer backward.'
  4. **Code, Test, and Analyze:** Write the clean, production-quality code for the optimal solution. As you write, briefly explain key lines. When finished, verbally trace one or two examples (including an edge case) through your code to prove it works. Finally, restate the final time and space complexity.

Putting It Into Practice: A Worked Example

Let's apply this script to a common problem: "Given an array of positive integers and a number 'K', find the maximum sum of any contiguous subarray of size 'K'."

Step 1: Clarify and Brute-Force

Okay, the goal is the max sum of a *contiguous* subarray of a fixed size, K. My initial brute-force approach would be to generate every possible subarray of size K. I could use a loop from the start to the end of the array, and for each starting point, have an inner loop that sums the next K elements. This would work, but it would have a time complexity of O(n*K) because I'd be re-calculating sums for overlapping windows.

Step 2: Identify Bottleneck & Name the Pattern

The inefficiency is definitely the re-summing of elements. When the window of K elements moves one step, n-1 elements are the same. This problem of operating on a contiguous subarray is a perfect fit for the **Sliding Window** pattern. It will let me calculate the sum for each new window in constant time, bringing the overall time complexity down to O(n).

Step 3: Explain the Optimal Logic

My plan is to first calculate the sum of the initial window (the first K elements). I'll store this as my current maximum. Then, I'll iterate through the rest of the array just once. In each iteration, I will 'slide' the window by adding the next element to my running sum and subtracting the element that just left the window. After each slide, I'll compare the new window's sum to my stored maximum and update it if necessary.

Building Your Vocabulary: Patterns and Their Verbal Cues

This framework is only effective if you can recognize the patterns. Study these common patterns and listen for their trigger keywords in the problem description.

  • **Sliding Window:** Cue: 'contiguous subarray/substring', 'longest/shortest/maximum' range.
  • **Two Pointers:** Cue: 'sorted array', 'pair of elements', 'subarrays', comparing from opposite ends.
  • **Fast & Slow Pointers:** Cue: 'linked list cycle', 'middle of a linked list', 'find duplicate number'.
  • **BFS (Breadth-First Search):** Cue: 'shortest path on unweighted graph', 'level-order traversal'.
  • **DFS / Backtracking:** Cue: 'all possible combinations/permutations', 'find all paths'.
  • **Heap (Priority Queue):** Cue: 'top K elements', 'Kth largest/smallest', 'median in a stream'.

How to Practice Your Interview Script

Knowing the script is half the battle; delivering it smoothly under pressure is the other. The key is deliberate practice. Don't just solve problems silently—narrate your solution out loud, following the 4-step framework every time. Record yourself and listen back to find areas for improvement.

For a more realistic experience, you can use an AI interview assistant to simulate the pressure of a live session. Acedly's **Mock Interview** feature provides a space to practice common algorithm questions while rehearsing your narration. It helps build the muscle memory you need to communicate clearly and confidently when you're in a real interview on Zoom, Google Meet, or Microsoft Teams. This practice transforms theoretical knowledge into a polished, interview-ready performance.

Try Acedly AI during your next interview.

Real-time guidance in a private overlay, in under 200ms. Free to start — no credit card.