The three step guide to coding interviews
For a while now I've been running a girls' competitive programming group, and one of the members shared with me her process for tackling problems. There’s a lot of overlap between competitive programming and the kind of questions you get during technical tests, so I thought I would share it:
- If it’s a graph problem, try depth-first search
- If it’s a regular problem, try binary search
- Otherwise, form recurrence relationship and solve with dynamic programming
That third step is a bit understated, but the gist of it is sound. If you can’t figure out a LeetCode or HackerRank problem, then you should have a list of strategies you can pull out and test. A lot of the problems you encounter are simply remixed from other problems, and it’s just a matter of pulling out the correct algorithm or data structure.
The main thing I’d add to her list is to try sorting the data and seeing whether that improves things at all. It’s surprising how often a solution presents itself once the data is ordered.