🎓 A1Learner
🔍
0 of 47 lessons completed

Thinking Out Loud While You Code

Thinking out loud is speaking the plan while writing code. It lets the interviewer follow the reasoning step by step.

Spoken steps

The steps below are spoken in order during a round.

steps = ["Restate the goal", "Name the approach", "Work one small example", "Write the code", "Check the result"]
for i in range(len(steps)):
    print(str(i + 1) + " " + steps[i])

Restating a problem

A restatement fixes the input and the expected output.

numbers = [3, 1, 4]
print("Input " + str(numbers))
print("Goal largest number")
print("Expected 4")

Checking by hand

A hand check follows the running total step by step.

total = 0
for n in [2, 5, 1]:
    total = total + n
    print("Add " + str(n) + " total " + str(total))

Example

steps = ["Restate the goal", "Scan each number", "Keep the largest so far"]
for step in steps:
    print(step)
numbers = [3, 7, 2]
largest = numbers[0]
for n in numbers:
    if n > largest:
        largest = n
print("Largest " + str(largest))

Key points

  • Thinking out loud starts with the goal in plain words.
  • It restates the input and the expected output.
  • It names the approach before any code is written.
  • It checks the plan on one small example.
  • It states each change to the plan as it happens.
  • Silence leaves the interviewer guessing about the plan.

The program first prints the spoken steps in order. It then scans each number and keeps the largest one seen so far. The final line shows the largest number found.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Python Playground

Exercise

What is the best first spoken step in a coding round?