Coding Interview Prep
Steps
Understand the question
Ask questions to clarify the question.
State a concrete example (input + output) of the problem. After understanding the question, the first thing to do is draw examples. Find a typical simple example and some simple corner case examples. By analyzing the example, we may get an idea about the rule behind.
Ask the interviewer what time and space complexity he would like in the solution. It can help you identify if the interviewer cares more about the thinking process or the best solution.
Solve the problem (think out loud)
Work on the example to find the idea
Start from the brute force solution
Improve with a better solution
Find a better data structure
Find a better algorithmic technique
Apply tricks for the data structure/algorithmic technique
Work on corner cases
Write unit test?
Analyze time and space complexity
Best Practices
Skip implementing anything that is trivial. Use basic libraries for parts that are not the main algorithm. Ask the interviewer if it is OK. If it's not, write another function for it.
Handle top-level algorithm first, then the functions you used in the main algorithm but are not defined. Add TODO comments for the part that you want to come back to. Make sure let the interviewer know it.
Assume valid inputs. It's not the core problem to check if inputs are valid. So clarify this assumption with the interviewer and take it for granted.
Whiteboard coding is different.
Skip documentation since it takes longer to write on whiteboard.
Keep identifiers short and have a convention for identifiers, e.g. i, j for array indices, A, B for arrays, s for string, d for dictionary, etc.
Tips for Python
Testing == is faster than testing >= or <=. So whenever we can narrow down to ==, don't use >= or <=.
Last updated