Cracking The Coding Interview 6th Edition — Solutions in Python

Hassaan Naeem
2 min readApr 4, 2022

Python solutions for CTCI 6th Edition.

Photo by Jefferson Santos on Unsplash

Brief Outline

I had some time and decided to take a crack at all the questions. Still a work in progress, as there are a plethora of questions. The master file in the git repo contains all solutions, all in Python. It may appear a bit messy, but can be followed sequentially with each question in the book, which are labelled in the code. Some questions have explanatory comments outlining solutions while some do not. Quite a few of the problems have multiple solutions, these are just different methods to solve the respective problem, and in most cases are just further optimized from the initial solution. Some problems reuse classes (e.g TreeNode, ListNode, etc.) defined earlier in the code. I have commented time and space complexity information for (basically) every problem, if any disagreement, point it out.

See the git repo: https://github.com/l4fl4m3/ctci

EDIT 2022/04/27: After a few grueling weeks, all the problems are now completed. I did however skip a bunch of chapters. Chapters 12 and 13, since they are with regards to C++ and Java, respectively. Apart from a few problems, most or all of chapters 9, 11, 14, and 15 were skipped due to the explanatory nature of the questions. The only other incomplete chapter is 7, with most problems completed, apart from a couple at the end, due to the repetitive nature of the problems. The chapter files have been labelled in the git repo. There are multiple methods and or solutions for many of the problems. Time and space complexities are present for each solution, apart from maybe one or two problems where I was a bit lost and or confused in deriving a complexity. Again, if anyone ever uses this, point out any errors!

--

--