Cracking the Coding Interview: 189 Programming Questions and Solutions

by: Gayle Laakmann McDowell (0)

I am not a recruiter. I am a software engineer. And as such, I know what it's like to be asked to whip up brilliant algorithms on the spot and then write flawless code on a whiteboard. I've been through this as a candidate and as an interviewer.

Cracking the Coding Interview, 6th Edition is here to help you through this process, teaching you what you need to know and enabling you to perform at your very best. I've coached and interviewed hundreds of software engineers. The result is this book.

Learn how to uncover the hints and hidden details in a question, discover how to break down a problem into manageable chunks, develop techniques to unstick yourself when stuck, learn (or re-learn) core computer science concepts, and practice on 189 interview questions and solutions.

These interview questions are real; they are not pulled out of computer science textbooks. They reflect what's truly being asked at the top companies, so that you can be as prepared as possible.
WHAT'S INSIDE?

  • 189 programming interview questions, ranging from the basics to the trickiest algorithm problems.
  • A walk-through of how to derive each solution, so that you can learn how to get there yourself.
  • Hints on how to solve each of the 189 questions, just like what you would get in a real interview.
  • Five proven strategies to tackle algorithm questions, so that you can solve questions you haven't seen.
  • Extensive coverage of essential topics, such as big O time, data structures, and core algorithms.
  • A behind the scenes look at how top companies like Google and Facebook hire developers.
  • Techniques to prepare for and ace the soft side of the interview: behavioral questions.
  • For interviewers and companies: details on what makes a good interview question and hiring process.

Illustrations noteIllustrations: Illustrations, black and white

 

The Reviews

I’m sure this is a good book. However, you would think a book on software would have what language it is focused on readily available. It does not. I had to do research to figure it out... after purchasing it. Very annoying. For your info, its in java. If you’re not a java developer it’s useless til you decide you want to learn java. And by that time you’re probably working and don’t need an interview prep book. PUT THE LANGUAGE ON THE FRONT PAGE

Here, in Silicon Valley, it seems like EVERYONE knows this book. It seems like everyone who comes here from India and China knows it as well. I’m from Europe, and I had never heard of it. So I bought it. I read it. And I did some of the many excercises. Did I learn anything? Not really. Is it good for interview training? Absolutely, yes.PROs:+ The first few chapters are short recaps on what you should already know.+ There are hundreds of interview-like questions. Very algorithm-oriented. Which is indeed what tech companies ask.+ This book might indeed improve your chances at Apple, Google, Facebook, etc...CONs:- This book will NOT make you a better software engineer. It only helps you at the interview-part.

Proven - no one cares how good you are when interviewing with Major Tech Companies. Your real skills for future work and interview process have close to nothing in common. Everyone in Main Tech looks at how good have you studied this book. I find it awful, but if you want to land such a job - this book is a must. Book itself is good though if you just want to cover/refresh a list of IT topics.

I threw it away. Not just because not all the solutions are correct; not just because it's not even remotely adequate preparation for a coding interview; but because of both of those things, and the fact that I resent the entire premise of being asked stupid coding puzzles that have nothing to do with the job at hand.I've interviewed at Google, Facebook, Netflix, Amazon, Spotify, Oracle, Microsoft and a dozen other smaller companies. Got rejected from some, got offers from others, and I'm now an engineering manager at one of them. I still think coding interviews are a scourge on this industry that select for the types of people that study coding problems instead of how to write and deliver good software.

A person who works at Spotify recommended this book to me and encouraged me to apply at their company. After I made their acquaintance I came to this book listing to find that the very first comment discouraged me from purchasing the book because it was written in Java. This delayed my decision for a month, but later I purchased it anyway.After reading its very valuable plaintext content for about two weeks, I decided to visit the book's website to find that its GitHub repository provides transpositions of all of the book's problem into JavaScript, Python, Ruby, Kotlin, C#, Swift and more...So there you have it, if you're ready to level up with Data Structures and Algorithms, find out for yourself the value this book has to offer. Mark this comment as helpful so others may not be discouraged from purchasing a book that may just help them get the job and improve their career!

As programming interview prep books go, this one is currently the most popular of the bunch. It's OK, in that you'll find material to practice for the whiteboard interviews that are prevalent at big tech companies. But let's be honest: this whole ecosystem is toxic. Here's a lady who worked for a few years at Google (that's right -- she worked for a *few* years, and only interned at those other big names she mentioned), and has parlayed that rather limited work experience into an entire lifestyle business, where she coaches programmers on how to pass interviews. That should tell you something important: the interview-prep industry has completely decoupled itself from the actual job of programming!I've been writing software for a long time, and I'm competent at my job. I've worked at some well-known companies, and I've interviewed a LOT of people. But I'm here to tell you that even I can't pass one of these interviews without studying. That's a bad thing. If the goal of an interview is to identify competent programmers, we've gone far, far off the rails with these kinds of interviews.But of course, that isn't (entirely) the author's fault. She's just a cog in the machine, and profits by perpetuating it. Because the presence of books like these create a vicious cycle: prep book gets written; interviewees study/memorize answers; interviewers make questions "harder" to compensate; new book gets written! It never ends. The grinder continues to turn, and whereas ten years ago you could get a good job with some string or linked-list manipulation questions, now you've got people who consider whiteboard coding of topcoder elite questions to be the baseline measurement of programmer competency. That's nuts.You'll even run into lazy interviewers who take questions directly from this book, which is the ultimate in stupidity: if "good" candidates have prepared from the book, and you ask questions directly from the book, what are you really accomplishing, other than a test of memorization skills? And yet, this is distressingly common. I've seen it myself. I've had recruiters from major tech companies send me pages from this book so that I can "prepare" for their interviews. What now?This kind of crap only stops if the more senior amongst us simply *refuse* to do it anymore. New grads have no leverage, so it's up to the rest of us to stand up and demand change. If you work at a company, please, INSIST that your interview process avoid questions from this book. If you interview programmers, please, stick to questions that demonstrate actual day-to-day work competency. And yes, if you're interviewing and you have the leverage, stand up to companies that try to abuse you with this kind of demeaning nonsense.If we are to be professionals, we have to demand the career respect afforded to professionals. That includes not being treated like children when we are interviewed.

This got me through four interviews, and I got an offer from each one. I would recommend this to anyone, with two big provisos: (1) if you’re going for a domain specific position like compilers, make sure to read up on those separately; and (2) focus on the Moderate problems. The Hard problems frankly weren’t asked and it was much more important to have the whiteboard coding method down.

I graduated with a CS degree in 2014 and recently decided to find a new job. The first 200 or so pages are a great review for someone who wants to brush up on all of the "must-know" topics such as data structures, search algorithms, algorithmic complexity, sorting, etc. There are a handful of questions specific to each of these chapters.After the chapters comes a slough of example interview questions rated as easy/medium/hard, each with hints that interviewers might provide if you were to get stuck as well as a solution.Interviewing with companies can be a pretty grueling process so if you want a much better chance of landing the job the first time, I would highly recommend this book.

I got this because of the limits of a actual coping saw. I needed to cut tighter corners than a coping saw, which it does. the wire will cut any on any edge of the blade (top, bottom, sides). This benefit does come at a cost, it's a little harder to control your cut. I will need a little more practice to master it, but I do put some blame on the blades. The teeth seem to be inconsistent, during your stroke the blade feels like it siips intermittently. The bow and handle seem perfectly fine to me.

As mentioned many know and/or read the book, which increases the probability of being asked something quite related to its content. Personally, I was asked the same exact questions in quite a few companies without any modification. There is a variety of topics and algorithmic solutions provided in order to cope effectively and more confidently with similar problems. That being said, the coding interviews might be a self-defeating process. Gayle writes about the sharp, passionate candidate with a 3.71 GPA, with an extensive contribution to open-source projects (and thus coding) struggling to solve/code, on the spot, a well-known problem that others knew. And he was rejected. The data, as she mentions, wasn't there based on her judgment and the rest of the committee. The data is still there (GPA, years of experience, open-source contribution) but obviously are neglected or improportionately weighted, on the spot, in favor of a 30 min (?) process that an engineer/developer will never be called to perform in his job, and thus the interview probably has negligible predictability or weight. Developers or engineers will never solve or tackle a problem, on the spot, with do-or-die supervision. It is more likely to involve a time of refraining from answering, gathering info, analyzing the code or the problem in their workspace, and coming up for a presentation or discussion prepared. Struggling, that characterizes many devs in the interviews, and probably Gale, is more likely associated with lack of preparation or lack of availability in memory based on a difficult issue the candidate encounters for the first time, while another one might have checked it within the same week. And if it could have been the other way around, then we could probably agree that there is a factor of randomness.The low predictability or significance of "on the spot" judgments during interviews has also been mentioned by decision-makers (Daniel Kahneman) while many of the judges use solely their intuition. This is also mentioned by Gayle "After the interview, your interviewer will have a gut feeling which is translated to numeric score".What is worse, it is often communicated, based on my experience, that the problem/puzzle is there to evaluate how your brain thinks/works, with no acknowledgement of the lack of credentials, qualifications and domain knowledge of the committee to justify such confident claims.What is more important, the expertise and skills throughout the years, which have a considerable weight for candidates to perform and add value practically have been overridden by, on the spot, coding of a puzzle.The committee potentially is subject to the "substitution bias", they don't really answer the question "Should we hire him and test him based on his past experience, skills, and knowledge" but the "Can he solve/code this puzzle, on the spot, although he will never really need to repeat such a process in his new job".Expertise and experience in repeated tasks with similar parameters (utilizing a programming language for years, frameworks, infrastructure) produce highly calibrated individuals on the job duties [Judgment under uncertainty: Bias and Heuristics] and are not tested, in favor of an instant brainstorming of a problem.

must have the excellent background knowledge to understand. not for beginning programmers

Good book

Nice and solid book. Good luck to everyone!

While this is a great resource, there's so much information, that yo can't just read it and think you're good. you have to study it. Practice the problems found ant the end of every chapters and often times find additional sources on the internet. If you're willing to put the work in, you'll get LOADs out! Good luck

This is an excellent in-deep source of information definitely recommended to everybody who is preparing for the interview. If gives a lot of tips on the interview process with FAANG companies and not only along with questions and answers from the real interviews (I found several hard tasks I was asked on the interviews in the past). It also allows to rehash your knowledge of algorithms and programming and has different complexity levels.What i’d recommend to add is more complex Advanced SQL (ranking, case, CTE) and data mart design basics questions.But in general this is a priceless book definitely recommended not only for the interview prep but also for shaping your coding skills!

Very detailed and encyclopedic coverage of programming tasks. It would take months to work through them all. Not really a quick guide to interview questions, but more like a thorough book of programming exercises.

It's true everyone's heard of this book. Everyone in my boot camp bought it, I don't know if anyone actually read it through because it's so dense (literally and figuratively). A lot my classmates and I ended up getting really great jobs but we all used resources online. There are great tutorials on Udemy, YouTube, fireship.io and they explain it in the language you want to use. And a lot of these people are actually fun to listen to. There's no point in learning java if youre going to code in python or js. So I don't really recommend this book, especially if you're beginner. Like whose idea was to start this off with BigO and data structures (which aren't even explained well, just tells you to use them).

I’m 10 years out of college and needed to brush up on DSA for a senior engineer technical interview. I liked how the book was laid out and organized so I could quickly find the topics I needed to focus on and study. The book prepared me well and provided good tips for how to approach problems. I got the job!

A whistling kettle should be heard outside of the kitchen area.

Even with hearing aids it is barely audible standing right next to the stove.The whistle is why I bought it.Can I still return it? The packaging has been thrown away.Beautiful to look at, not great to use.

If you are a starting or seasoned developer going through gut-wrenching process of preparing for the current tech interview process this is probably one of the best resources in terms of letting you know that your experience or inexperience doesn't matter as long as you can solve the problems in this book. The author amusingly states that the interviewers are trying to see how you approach problems that 'you've never seen before' and then shows you 189 of the most common ones. It is significantly likely that although your coding interview with a FAANG-like company may not have of these problems exactly it will be some flavor of one or more of them. You will also likely have to solve them under time constraints that will likely not allow you to think through them as if you had never seen them before while the interviewer is waiting for your answer so repetitive practice is key. Know that your competition for these interviews could be spending hundreds of hours practicing the types of problems in this book while you may be doing useful work so you may have to take significant time out of your schedule to practice to be competitive. What that says about those who have successfully or unsuccessfully navigated the tech interview process is unclear. I suppose the idea is for technology companies to have a consistent interview process although a consistently bad interview process may miss more candidates than an inconsistently good one. But this is the system we are currently stuck with so I guess that you should play along until the tech companies evolve and a better technical interview process comes along.

I got it for my son who studies computer science. His comment: good! useful! :) He is happy and then I am happy.

Anyone who plans on being a dev or engineer should read. That being said, its so long and annoying. But that is life so buy the book

The questions and solutions are really helpful. However the only downside is the size of the book. It's very chunky and flipping between the book and laptop/keyboard is cumbersome. It would've been great if an ebook option was available on Amazon.

I’ve been meaning to review this book for a while. Last year I got laid off from my startup and found myself feeling anxious as I haven’t had to look for a job for several years. I bought this book along with two others, but this was the only one I really spent time on. The first third of this book provides specific information about companies along with example problems. The last two thirds are problem solutions with explanations. I found everything valuable. I didn’t write out complete solutions for most of her example problems. If I thought it was obvious I skipped it, but whatever you do don’t skip reading the solution. It’s here where you can read about ways of solving the problem that didn’t occur to you. For example, if you want to know if two binary trees are identical you can verify this by comparing their preorder and inorder traversals. The only gaps were discrete math and heaps. Heaps appeared frequently in sample questions on Glassdoor. I pulled an old data structures book out to re-read about heaps, but I was never explicitly asked about them during my job search though I did mention them a couple times as possible ways to maintain a priority queue.Information about the companies was very relevant as I live in the Bay Area. I wish I had heeded her admonition about discrete math for Google because I was unprepared for these questions. I would have read the math if it was in the book, but since I haven’t used that math ever in a job I skipped it. During the interview I was able to solve the math problems except I needed basic definitions and one or two hints. For Amazon it was good to know there’s a “bar raiser” because it was obvious when I met the interviewer who wrote out a really hard problem right off the bat and wanted a linear time algorithm. I was speechless for five minutes, but managed to reduce the problem enough where the solution suddenly came to me. I think I would have been unnerved by the question if I didn’t know about this type of interviewer that she writes about. I wish she also covered Twitter and LinkedIn.The book doesn’t talk enough about applying for jobs. I do wish she wrote about job offer contingencies as my first job offer was from a startup who told me it expires in 24 hours. This in turn caused other recruiters to panic. While in the end I got a good job, all in all I hope I’m not forced to do this again anytime soon. I’m just glad I had this book at my side. It was indispensable.

I was a little skeptical before ordering this, a $300 (now $224) grip... a grip!, does not even bring batteries with it. But the one beef I have with my new OM-D is getting used to the handling of its vintage body. I heard about this grip and read the reviews, which were raving, and coming from using an NEX-7 (that has great ergonomics), I wanted to be able to hold my new OM-D EM5 the same way. After 3 days of shooting with it, I decided to get my 300 bucks back and learned to get used to shooting without the grip. Why? before I start with the pros and cons of this item, please remember that this is MY opinion, because depending on who uses this, people will love it, hate it, not mind it, or like in my case: just don't need it...The good:+Much more comfortable than using the OMD-D without it+The grip feels solid, made of smooth/durable plastic/metal, perfectly integrates with the camera, in reality, it makes the OM-D almost a whole new different camera!+If you have a big zoom lens like the Lumix 12-35 f2.8 the grip helps balance the camera very well, allowing you to shoot with only one hand, very comfortable, very firm, non-slide material.+The position of the additional shutter button/trigger and turn dial feel much more natural on the the grip than on the camera itself.+When using both, the grip and the battery holder, this thing turns a "pocket" camera into a mini DSLR! with two shutter buttons for landscape/portraits and improving the hold on the camera.The bad (in my opinion):-Did I mention it costs $300? for a grip! Though it is well constructed and adds stability to the camera, I do not see $300 worth of value here, which is why I cannot give it 5 stars. Maybe if it was in the $130-50 price range.-When using both parts of the grip, it just makes the camera TOO big and bulky. Do we need the battery pack? why couldn't Olympus offer just the grip for a lower price?-(This maybe a bit superficial, but I think it's important so I'm going to say it anyway): You loose the OM-D vintage look, this grip makes the camera look more like a small DSLR, rather than the retro OMD look that we all love about this camera.-If you have big hands, and you use a large zoom lens (like the 12-35mm) your fingers get caught between the lens and the grip and all-of-the-sudden this is NOT so comfortable.--------------------------------------------I would give it 5 stars for what it is, and what it does, it certainly delivers, I love the additional shutter and dial buttons and how it becomes part of the camera instantly. But I hold my 5 star rating for two reasons:- 1st: Do you really need it? I don't think so (my opinion) you can easily do without it, you CAN get used to using your OM-D and griping it correctly, and get great shots! You can feel the difference between using the grip and not using it, but you can overcome that after some time using the camera.- 2nd: Not worth its value: at $300 this is an item that is way over-priced

First off at $299 this is a pricy accessory and barely worth the price. There is no way I would pay $399 for this grip.With that said this is the best grip I have ever owned and makes the OM-D behave like 3 different cameras.1) Without a grip. Put on the Pani 20mm and you have your go anywhere camera.2) With first part of grip you get a nice grip on the right side of the camera to help stabilize longer lenses another shutter release and another front control dial which changes either aperture or exposure compensation depending on which mode you have selected. This is the configuration I keep the OM-D in most of the time with the Pani 25mm f/1.4. This is a great combination.3) With the second part of the grip you now get a portrait shutter release and another front and rear control wheel. You also get 2 more function buttons which can be set independently of the first 2 function buttons. You also get a lock to prevent any of those buttons from accidentally being pressed. Finally, you get a space for an extra battery. Even in this configuration the camera is neither heavy or large. This set up is fantastic for the event photographer and portrait photographer. This setup makes this a fantastic professional camera for many many many situations. M4/3 has arrived into the working professional ranks with the OM-D and this grip.There are 3 main drawbacks to this grip. The first is the first part of the grip blocks off the battery compartment on the camera. So you have to take the grip off to recharge the batter. The second is on the second part of the grip the tripod lug is well to the right of the camera. I am really not sure what Olympus was thinking here. The 3rd and largest right now is the fact Olympus does not sell the BLN-1 yet. Which sort of makes the extra battery capacity a moot point.To solve the problem of no Olympus Battery, I purchased the following. ZIP OLYMPUS BLN-1 (Includes 1-1500mAh battery, pocket charger,LCD Screen protector and Card Reader) for Olympus OM-D E-M5 This battery does not work in the Olympus charger. However, it comes with its own charger that is also a car charger. This charge also charges the Olympus battery so you get a way to charge your Olympus batter in the car. So far I have had no issues with this product.Overall, if you have the OM-D and some of the larger lenses such as the 100-300mm or 14-140mm then this lens will help stabilize and balance the lenses on the camera making them much easier to use.ProsBest grip I have ever boughtTurns the OM-D into 3 different camerasGreat build qualityConsBlocks camera batter compartmentTripod lug not centeredNo Olympus BLN-1 batteries available to put in grip

First, I have no idea why Silicon Valley is obsessed with these interviews. Is it just that they couldn't figure anything else out? These questions are a terrible indicator of how good of a programmer you are. My software company, outside the valley, has interviews that actually relate to the job, and we get confused candidates because they've practiced all these algorithm and data structure problems and little else. Anyway, it's what we have and that's what the book is geared towards. It's a decent book. I like to have an "offline" thing to supplement my online training, and this fills that void. Unfortunately, it's not without its flaws. It needs a bit of a math review of the commutative property and logs, otherwise understanding that chapter is going to be difficult. It has an occasional "easily proved" or "easily disproved" type of verbiage which is never backed up. (This is something I see in far too many books.) The biggest flaw of the book is you can't ask clarifying questions about a problem, which you will most definitely need to do at an interview. That's more of a flaw of the format rather than the author. I'm not going to go into details of each of the problems, because I don't want to give anything away, but I remember doing the first problem and wondering why in the world they were suggesting doing a quicksort or other n log n algorithm on a string which is at most 26 characters.

I got it for my son who studies computer science. His comment: good! useful! :) He is happy and then I am happy.

The media could not be loaded.  Great source for anyone who is preparing for coding interview. One of my professors recommended it and I got it. It is a great book

Not a a book I would read cover-to-cover, but an excellent reference material.

Cracking the Coding Interview: 189 Programming Questions and Solutions
⭐ 4.7 💛 8165
paperback: $20.27
Buy the Book