-
Listen carefully -> Lookout for every detail mentioned in the question -> are you using all the relevant details that are mentioned in the problem definition
-
Draw an example -> But be careful, you should use a example which is general to the problem -> Not a special case -> sufficient large example "not very small"
-
State a brute force solution -> once you have the example, immediately come up with a Brute Force solution
-
optimize your solution -> Look for any unused infomation (which is mentioned in the problem definition ) -> Use a fresh example ( that will help you to see the problem from different prespective ) -> solve it "incorrectly" ( like having brute force solution will help to find the optimize one similarly having the incorrect/partially correct solution will help to find the right solution ) -> make time vs. space trade off -> precompute information -> use a hash table -> Think about best conceivable time
-
Implement
-
Test
- Look for BUD ( BottleNecks, Unneccessary work, Duplicated work )
- Do it Yourself ( Grab a pen and paper, and find out the solution for the problem )
- Simplify and Generalize
- Base case and build
- Data Structure Brainstrom
- Best conceivable runtime (BCR) -> tells you about the best acheivable time complexity -> also tells you about that we are done optimizing the time complexity and we can play with the space complexity of our solution
Reference: Cracking the coding interview by Gayle Laakmann Mcdowell