Overview
Overall, you will find that many leetcode problems are similar to one another. Once you build a solid foundation of knowledge (Blind 75) you will be able to conquer any problem! Keep this in mind when you are looking for patterns within problems. If a string problem stumps you, try thinking of it from an array perspective and vice versa! When I think about Leetcode solutions, I take the following steps:
The process
- Clarify the question with your interviewer. ASK QUESTIONS! Don't rush into it.
- Understand the problem. Know WHY the answers are correct vs incorrect.
- Approach a Brute Force solution, in THEORY but do not code yet.
- Write some pseudocode for your brute force solution.
- Run through test cases, on your pseudocode to make sure it works. (Time permitting)
- Identify bottlenecks, and optimize as necessary.
- Code the final solution.
- TEST!
Testing
When testing our solutions, it's always good to think about edge cases to test against. This shows our interviewer our deep knowledge of the underlying data structure, as well as the ability to think outside of the box. Here is my (not so) exhaustive list of testing criteria for arrays and strings.
Arrays
- Nil input value
- Empty array
- Single value in array
- Repeating values in the array
- Large array
Strings
- Nil input value
- Empty string
- Special characters in strings (ie. $%^&#😎😃)