Interview Formula

Before you code

Read the prompt out loud. If you can’t understand how the example input leads to the output, you don’t understand the problem. Ask the interviewer for clarification.

Give an example test case or possible edge case input and expected output. Then ask the interviewer if it’s correct. If it is, you won’t misinterpret the question.

Talk about the algorithm you’re going to use. Mention out loud what you’re thinking about and whether your approach will solve the question or not. Start with the brute force method to show you understand the problem and expected outputs.

Directly ask your interviewer if they want you to code that solution or not. They’ll let you know if they’re happy with your approach or if they want you to give something more optimal where you will think out loud again.

While you’re coding

Code Out loud. Explain out loud what each line of code you’re writing is doing any what part of the algorithm you mentioned earlier is addressing. If your algorithm needs to use binary search then emphasise when you’re coding binary search and how it follows the algorithm you outlined.

Point out what you’re going to code for later. There’s portions of code you don’t have to look at as you’re writing initially. As an example, for null checks you can put a comment mentioning //ToDo: Null Checks. You'll come back to this portion after implementing the main solution.

Talk about optimisations and bottlenecks as you go. Mention as you’re coding if any portion is suboptimal, you recognise it, and you’ll come back to it afterwards. You don’t have to code the perfect solution on the first written iteration.

Confirm the interviewer understands what you wrote. Slow down after you complete a portion of writing code and confirm with the interviewer if they understand what you wrote so far. Dry run your code with an example test case and talk about what the output should be up to the point you coded.

When you’ve completed your first iteration, ask the interviewer if they would prefer you to:

  1. Dry run your code against the example inputs

  2. Optimise your code further

Dry run your code against the example inputs. Go through your code and reference again what portion of code your coding is covering line by line. As you’re going through it, talk about what the state of the output should look like as you go along. If there are bugs, you have to focus your attention on resolving each of them.

Optimise your code further. If there are bottlenecks in your code, point them out, explain why the bottleneck is there and what you’re going to do to optimize them. Talk out loud what you’re thinking and why certain approaches you’re thinking do or don’t work to optimize the algorithm. When you do come up with an improved solution, ask again if the interviewer is happy with that approach and if they want you to implement it.

Solve for the running time. Go through the code line by line and comment what the running time is for each function and for loop. Explain where the bottlenecks are and how they can be improved. Do not simply assert the running time complexity.

Last updated