Skip to content
Skip to article
THE VERVIA GUIDEBOOKSoftware Engineering
Software Engineering5 min read

Communicating While Coding in Interviews

Learn how to think out loud in coding interviews without narrating every keystroke, overexplaining, or going silent.

A practical guide to your next interview.Start reading
On this page9 sections

Quick Answer

Explain the problem, make your assumptions explicit, compare an approach, and talk at the decisions that affect correctness. When you test, explain why the case matters. You do not need to narrate each keystroke or fill every pause.

Microsoft’s technical interview guidance discusses clarification, planning, testing, and complexity. The miniature coding conversation below is Vervia Editorial’s independent practice example, not a Microsoft question or evaluation.

Make a contract before an implementation

Consider this practice problem: given a list of integers and a target, return the indices of two distinct elements whose values add to the target. For this exercise, assume you may return any valid pair and should return no result when none exists.

Those details matter. Returning values is different from returning indices. Using the same element twice is different from using two elements that happen to have equal values. Sorting may change indices unless you retain the original positions.

An opening clarification could be:

Example

Do you want the original indices, and can I return any valid pair? I’ll treat the two elements as distinct positions and return no result if there is no pair.

In a real interview, ask rather than silently selecting requirements. If the interviewer gives a different contract, adapt the implementation and tests to that contract.

Explain the change from a simple approach

A direct method tries each pair of distinct positions. The number of pairs grows quadratically with the list length, so that approach takes O(n²) time and needs only constant extra working space if you do not copy the input.

A hash map can store each previously visited value and an index where it appeared. At each position, look for the value that would complete the target sum. This uses expected O(n) time with O(n) extra space under ordinary hash-map assumptions. State the space cost along with the time benefit.

An explanation with a tradeoff is:

Example

Checking each pair is simple but repeats work. I can keep a map of earlier values to indices, then look for the current value’s complement. That uses extra space to avoid the nested scan.

Do not say “a map is always faster.” Explain the comparison for this problem and the assumptions behind it.

The order of operations is a correctness decision

For each value, perform these steps:

  1. Compute the complement: target minus the current value.
  2. Check whether that complement is in the map of earlier elements.
  3. If it is, return the stored index and the current index.
  4. Otherwise store the current value and its index, then continue.

The map must contain earlier elements when you check it. Checking before inserting the current value prevents using the same position twice. That is an important thought to say aloud; naming the map variable is usually less informative.

For input [3, 3] with target 6, the first 3 is stored. The second 3 finds the earlier index, so the result uses two positions. A single-element input [3] with target 6 must not return a pair.

A decision-focused coding conversation

The following is fictional practice dialogue, not an actual interview transcript.

Example

I’m returning original indices, so I’ll preserve the index as I scan. Before inserting the current value, I’ll check whether its complement was seen earlier. That order prevents pairing an element with itself. If the lookup fails, I’ll store this position and continue. If the scan ends without a pair, I’ll return no result as agreed.

Contract: The first sentence connects an output requirement to what is stored.

Invariant: “Seen earlier” explains what the map represents at the start of an iteration. It is stronger than simply saying “I use a dictionary.”

Correctness: The third sentence gives a reason for the order of operations. A listener can inspect that claim against the code.

Completion: The final sentences account for both a match and the no-pair case. They do not leave the function’s ending implicit.

This explanation is useful at a decision point. Once the interviewer understands it, you can write a few lines quietly and then test rather than repeating the same reasoning during every assignment.

Choose tests that challenge the reasoning

Instead of running only a friendly example, prepare cases tied to the contract:

  • Two equal values: [3, 3], target 6. Tests whether duplicate values can use distinct indices.
  • One value: [3], target 6. Tests accidental self-pairing.
  • Negative and positive values: [-2, 5, 8], target 3. Tests complement logic without an all-positive assumption.
  • No pair: [1, 2, 4], target 8. Tests the agreed no-result behavior.
  • More than one valid pair: [1, 4, 2, 3], target 5. Tests whether returning any pair matches the requirement.

For each case, predict the result before running it. Trace the map’s contents when the prediction and output differ. “The sample passed” is weaker evidence than explaining what a case rules out.

Say what you are doing when you get stuck

A useful pause has a purpose: “I’m checking whether this branch can return the same index twice.” That gives the listener a specific issue to follow. Repeating “I’m thinking” adds little information.

If a bug appears, use a small counterexample. For the insert-before-check mistake, one element with a target twice its value exposes the problem. State the failure, change the order, and rerun both the counterexample and a valid duplicate case.

If you need a hint, identify the gap: “I understand how to store earlier values; I’m unsure how to preserve original indices if I sort.” The interviewer can respond to a concrete question.

Practice the conversation without Vervia running your code

Use a local editor for this exercise. First explain the contract, then implement your chosen approach, then run the edge cases. Finally describe the time and space costs and one alternative. Keep those activities distinct from evaluating a spoken behavioral answer.

Vervia’s current individual behavioral practice does not execute code or verify algorithm correctness. Read the software engineering practice overview for current scope, or the technical project guide to practice explaining work you actually built.

Sources and practice notes

Microsoft’s technical interviewing resource supports preparing to clarify, plan, test, and explain complexity. The problem contract, algorithm walkthrough, fictional dialogue, and test set here are Vervia editorial exercises, not a reproduction of an employer interview.

For feedback on a different kind of answer, inspect the complete behavioral feedback example. Its score does not validate the algorithm in this guide.

Put it into practice

Try a short spoken answer.

Choose a behavioral question, record your answer, and get feedback on its clarity and structure. Use your own experience rather than memorizing an example. See how behavioral practice works or check current pricing.

Practice an answer

Read a complete feedback example before signing up.

About this guide

Written by Vervia Editorial using established interview frameworks, public recruiting guidance, and illustrative practice examples.

Published
Last reviewed
Read our editorial policy
Browse all guides