This repo contains Python and C++ solutions for Gayle Laakmann McDowell's Cracking the Coding Interview 6th Edition. Admittedly, there are lots of other GitHub repos with solutions for this book. But when you're studying and are deeply confused, how do you know that their code actually works? If it's untested, then you don't! That's why the philosophy of this repo is that every solution must have one or more tests using the Python unittest framework or the C++ Catch framework. We enforce the unit tests using Travis CI automated testing ensuring that the solutions are made of living code that gets executed and tested on every single public commit. Reference and contribute solutions with confidence!
- Chapter 1 - Arrays and Strings:
9 / 9
complete. - Chapter 2 - Linked Lists:
8 / 8
complete. - Chapter 3 - Stacks and Queues:
6 / 6
complete. - Chapter 4 - Trees and Graphs:
11 / 12
complete. - Chapter 5 - Bit Manipulation:
7 / 7
complete. - Chapter 6 - Math and Logic:
0 / 10
complete. - Chapter 7 - Object Oriented Design:
0 / 12
complete. - Chapter 8 - Recursion and Dynamic Programming:
11 / 14
complete. - Chapter 9 - System Design and Scalability: N/A
- Chapter 10 - Sorting and Searching:
0 / 11
complete. - Chapter 11 - Testing: N/A
- Chapter 12 - C and C++: N/A
- Chapter 13 - Java: N/A
- Chapter 14 - Databases: N/A
- Chapter 15 - Threads and Locks:
0 / 4
complete. - Chapter 16 - Moderate:
1 / 26
complete. - Chapter 17 - Hard:
3 / 26
complete.
Total: 55 / 145
- Chapter 1 - Arrays and Strings:
3 / 9
complete. - Chapter 2 - Linked Lists:
4 / 8
complete. - Chapter 3 - Stacks and Queues:
0 / 6
complete. - Chapter 4 - Trees and Graphs:
0 / 12
complete. - Chapter 5 - Bit Manipulation:
4 / 7
complete. - Chapter 6 - Math and Logic:
0 / 10
complete. - Chapter 7 - Object Oriented Design:
0 / 12
complete. - Chapter 8 - Recursion and Dynamic Programming:
5 / 14
complete. - Chapter 9 - System Design and Scalability: N/A
- Chapter 10 - Sorting and Searching:
0 / 11
complete. - Chapter 11 - Testing: N/A
- Chapter 12 - C and C++:
1 / 6
- Chapter 13 - Java: N/A
- Chapter 14 - Databases: N/A
- Chapter 15 - Threads and Locks:
0 / 4
- Chapter 16 - Moderate:
0 / 26
complete. - Chapter 17 - Hard:
0 / 26
complete.
Total: 17 / 151
Python and C++ unit tests are in tests.py and tests.cpp respectively. Python and C++ solutions are organized by chapter in python_solutions and in cpp_solutions respectively.
The repo contains a makefile that handles all dependency installations for you 😄. Execute the following depending on your OS:
Mac usage requires the package managers Homebrew and Pip which is done for you in the Makefile:
git clone https://github.com/alexhagiopol/cracking-the-coding-interview.git
cd cracking-the-coding-interview
make configure-mac
git clone https://github.com/alexhagiopol/cracking-the-coding-interview.git
cd cracking-the-coding-interview
make configure-ubuntu
The best way to work in Windows is to install Bash on Ubuntu on Windows, then enable graphical applications to use favorite IDE, and finally follow the Ubuntu installation instructions above.
In the root directory, execute the following to run all tests in Python and C++:
make test
This will show exactly which lines are not covered by tests in each Python source file:
pip install coverage
make test_coverage
The goal of this project is to write a tested Python and C++ solution for every problem in the 6th edition of the textbook. I definitely need help! PRs are of course very welcome. The work has become quite time consuming because each solution is living code that actually gets executed. Thus, each solution needs its own small dataset and infrastructure in order to be tested. Just writing the test for a problem is often harder than solving the problem itself. Here are some ways you can help:
- Fixing bugs 🐛.
- Solving unsolved problems in either language (see the completion progress in the table of contents).
- Improving existing solutions with better performance or clarity.
- Adding more unit tests or refactoring to increase the test coverage %.
- Implementing C++ test coverage measurement using gcov.
- Integrating automated unit test coverage % measurement and reporting for both Python and C++ via Coveralls.
- Adding solution descriptions in English for problems that don't have them.
If you have any contributions, please make a PR to the master
branch. Feel free to message me for clarification on any of
the above items.