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:
Dry run your code against the example inputs
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