How to Prepare

1. Listen Carefully

Be sure to record any unique information in the problem.
For example, if the question starts with "Given two arrays that are sorted", the optimal algorithm for the sorted solution is probably different from the unsorted one.

2. Draw an Example

You have to create an example that is specific (that uses real numbers or strings), sufficiently large and as general as possible.

3. State a Brute Force Algorithm

Even if it's obvious for you, it is not necessarily obvious for all candidates. Despite being slow, explain the 1.1 Big O#⏱️ Time complexity and the 1.1 Big O#💾 Space Complexity of the algorithm.

4. Optimize

5. Walk Through

Solidify your understanding of the algorithm. If you made some mistakes in the previous parts and you start coding, it will take longer to fix first the algorithm, and then the code.

6. Implement

Do this preferably on paper.
Remember:

7. Test

Hand testing is very slow very long time to find small errors.
Remember:

  1. Just read and analyze what each line of code does.
  2. Double check weird looking code and hot spots like:
    • x = length - 2
    • for(int i = 1; ...)
    • Base cases in recursion
    • null nodes
  3. Small test cases.
  4. Special cases (null or single element values ecc.).