A growing collection of Python interview problems explained from first principles.
Each solution includes:
- The original problem contract
- Intuition and pattern recognition
- A step-by-step approach
- Complexity analysis
- A worked dry run
- Clean, executable Python
- Focused test cases
The purpose of this repository is not to claim novel algorithms. It documents how I understand, explain, implement, and test common interview patterns.
| # | Problem | Pattern | Difficulty | Time | Space |
|---|---|---|---|---|---|
| 1 | Two Sum | Hash map | Easy | O(n) |
O(n) |
| 13 | Roman to Integer | Hash map and scan | Easy | O(n) |
O(1) |
| 14 | Longest Common Prefix | String scanning | Easy | O(S) |
O(1) |
| 20 | Valid Parentheses | Stack | Easy | O(n) |
O(n) |
S is the total number of characters inspected across all input strings.
The repository uses only Python's standard library.
python3 -m unittest discover -s tests -vpython-interview-solutions/
├── problems/
│ ├── 0001-two-sum/
│ ├── 0013-roman-to-integer/
│ ├── 0014-longest-common-prefix/
│ └── 0020-valid-parentheses/
├── tests/
└── README.md
For every problem, I follow the same sequence:
- Restate the input and output.
- Walk through a small example.
- Describe a correct brute-force approach.
- Identify repeated work or a useful ordering property.
- Select the appropriate data structure.
- Implement and test the optimized solution.
- State time and auxiliary-space complexity.
Problem names and descriptions refer to common programming-interview exercises. Explanations and implementations in this repository are written for personal learning and interview preparation.