A pattern cheat sheet with tested solutions
The problem
Build your own reference of the interview patterns: for each one, a signal that tells you to use it, a short template, and a tested solution to one problem.
Requirements
- Cover at least eight patterns from the course, each with its signal phrase
- Write a Python function for each, with its time and space complexity in a comment
- Add at least three test cases per function, including an empty input
- Include a brute-force version for two problems and compare the results on random inputs with a fixed seed
Technologies
- Python 3
- collections, heapq and bisect
- assert statements for tests
- random with a fixed seed
Step by step
- List the patterns and write the signal that points to each one.
- Write one problem and one function per pattern.
- Add tests, including empty and single-element inputs.
- Compare two fast solutions with brute force on random inputs.
Expected result
A single Python file where every pattern has a template, a tested solution and a stated cost, which you can read before an interview.
How it is evaluated
- Every function passes its tests
- Each pattern has a clear signal and complexity
- Brute force and fast versions agree on random inputs
- The code is clean and uses descriptive names
Ways to improve it
- Add a timing comparison that shows the speed difference
- Add two more patterns, such as union-find or tries
- Add a one-line spoken explanation for each pattern