/cci-solutions

My solutions to exercises in Cracking the Coding Interview, in Python

Primary LanguagePython

cci-solutions

My solutions to exercises in Cracking the Coding Interview, in Python.

I've named files like cci_##.py, where ## is a chapter number. All answers for a chapter are written in a single file, with little asserts to test each one right after its implementation. Simply run the file to check all these tests.

Some helpful or fun utilities I've had to build and use along the way:

  • cci_01.py's seven function rotates an NxN matrix in place, which I ended up using in a test for a problem in a later chapter.
  • from cci_02 import Node for linked lists (singly-linked or doubly)
  • from cci_04 import TreeNode for binary trees
  • cci_07.py has implementations of a HashTable with external chaining, an example of how to make a class iterable (see CircularList), Minesweeper, and Othello
  • from cci_10 import BitVector for a bit map
  • This pytest example demonstrates a complementary approach to chapter 11, which is focused much more on the high-level.
  • cci_14.py for examples of how to use sqlite3
  • cci_15.py for examples of how to use threading
  • cci_17.py's two is an implementation of the Fisher-Yates shuffling algorithm, which I use in a test further down.

Note that when importing all the code in the corresponding file gets run, because I haven't been careful enough to put things in if __name__ == '__main__': blocks.

Chapter names n_problems Done
1. Arrays and Strings 9
2. Linked Lists 8
3. Stacks and Queues 6
4. Trees and Graphs 12
5. Bit Manipulation 8
6. Math and Logic Puzzles 10
7. Object-Oriented Design 12
8. Recursion and Dynamic Programming 14
9. System Design and Scalability 8
10. Sorting and Searching 11
11. Testing 6
12. C and C++ 11
13. Java 8
14. Databases 7
15. Threads and Locks 7
16. Moderate 26
17. Hard 26
Σ 189 189