Cracking The Coding Interview Github For Mac

Cracking The Coding Interview Solutions with Automated Unit Tests

  • C++ Solutions
  • Python Solutions
  • Automated Unit Tests
  • Active Development
  • Multiplatform Support: Mac, Linux, and Windows

Oct 01, 2012  Dice.com recently interviewed Gayle Laakmann McDowell, author of Cracking the Coding Interview, who gave a white board demonstration. Category Science &. My background; How I landed interviews with top tech companies in the world: Facebook. Cracking The Coding Interview: Great for covering foundational CS coding problems. CodeRunner: I love this Mac app! Linux Command Line Guide JavaScript Example Git Tutorial React Tutorial Java Tutorial.

Introduction

This repo contains C++ and Python solutions for Gayle Laakmann McDowell's Cracking the Coding Interview 6th Edition.Admittedly, there are other GitHub repositories with solutions for this book. Buthow do you know that their code is actually correct? If it's untested, then you don't!

In this project, every C++ solution has unit tests using the C++ Catch framework,and every Python solution has unit tests using the Python unittest framework.We enforce test correctness automatically using continuous integration serversensuring that the solutions are made of living code that gets executed and tested on every single commit. To my knowledge, this isthe Internet's only solutions repository with this level of testing rigor: >90% automated test coverage means you canreference and contribute solutions with confidence.

Table of Contents

C++ Solutions:

  1. Chapter 1 - Arrays and Strings: 9 / 9 complete.
  2. Chapter 2 - Linked Lists: 8 / 8 complete.
  3. Chapter 3 - Stacks and Queues: 4 / 6 complete.
  4. Chapter 4 - Trees and Graphs: 11 / 12 complete.
  5. Chapter 5 - Bit Manipulation: 7 / 8 complete.
  6. Chapter 6 - Math and Logic: 0 / 10 complete.
  7. Chapter 7 - Object Oriented Design: 0 / 12 complete.
  8. Chapter 8 - Recursion and Dynamic Programming: 8 / 14 complete.
  9. Chapter 9 - System Design and Scalability: 0 / 8 complete.
  10. Chapter 10 - Sorting and Searching: 10 / 11 complete.
  11. Chapter 11 - Testing: 0 / 6 complete.
  12. Chapter 12 - C and C++: 10 / 11
  13. Chapter 13 - Java: N/A
  14. Chapter 14 - Databases: 0 / 7 complete.
  15. Chapter 15 - Threads and Locks: 0 / 4 complete.
  16. Chapter 16 - Moderate: 11 / 26 complete.
  17. Chapter 17 - Hard: 1 / 26 complete.
  18. Miscellaneous Exercises: 2 complete.

C++ Total: 81 solutions complete.

Python Solutions:

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

Python Total: 58 solutions complete.

Grand Total: 139 unique solutions complete.

Building:

Mac:

Mac usage requires installing the package managers Homebrew and Pip which is done for you in the Makefile:

Ubuntu:

Windows:

For Windows users, I recommend developing this project using the Windows Subsystemfor Linux (WSL) featureof Windows 10 and then following the Ubuntu build and testing instructions inside WSL.This recommendation is due to the use of Ubuntu, CMake, and makefile based build and executionsystems on the servers that automatically test changes to the code. For more on Windowsdevelopment, see the Appendix section at the end of this page.

Testing:

Testing is the most important part of this project: onlythe unit tests define the problem being solved. In the rootdirectory, execute the following to run all tests in Python and C++:

make test is the command I use most while developing this project. My workflow follows:

  1. I read a problem and encode the problem definition by implementing its unit tests.
  2. I execute make test to see where the project fails to satisfy the unit tests.
  3. I add to the implementation of the problem solution until make test succeeds.

Optional: Generating a Test Coverage % Report Locally (Python support only):

This will show exactly which lines are not covered by tests in each Python source file:

Contributing

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, so PRs are welcome. There is much to do because each solution needs its ownsmall dataset and infrastructure in order to be tested. Here are some ways you can help:

  1. Fixing bugs 🐛.
  2. Solving or improving solutions to problems in either language (see the completion progress in the table of contents).
  3. Adding more unit tests to increase the test coverage %.
  4. Implementing automated C++ test coverage measurement using gcov.
  5. Integrating automated test coverage % reporting for both Python and C++ via Coveralls.
  6. Adding prose solution descriptions 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 ofthe above items.

Appendix: Windows Development

On my own Windows machine, I develop using CLion runningnatively in Windows and test the code using make test in a WSL terminal window.For users who do not want to use WSL, I have developed the build and test methodology below:

Building

The project can be developed purely on Windows without WSL by using Visual Studio 2017.First clone the code:

Then, install Python3 and numpy using your method of choice. I prefer installing Python3 and pip3 fromthe official website then installing numpy via pip:

Then, open the project in Visual Studio 2017 which has CMake support.I've found that best the workflow is to use Visual Studio to edit code and use debugging functionality. Beforebuilding the code, you must follow these instructionsto tell Visual Studio to download PDBs it needs. Additionally, this articledescribes Visual Studio CMake support in more detail if you're interested. A CMakeSettings.json file in the root projectdirectory sets the location of the Visual Studio build folder to be inside the root folder of the project.

Testing

Running the tests and seeing their output is best done from a PowerShell window since VisualStudio in CMake modedoes not allow the console output of the tests.exe and tests.py files to remain visible even when pressingCTRL + F5 as described in this post which applies to'normal' Visual Studio use. I am monitoring the situation re: Visual Studio, and when I find better solutionsI will implement them or post them. If you know of something better, please contact me.

In the meantime, from the project root directory, you can run the Python tests using ..

.. and you can run the C++ tests using ..

Cracking the Coding Interview is the result of my first-hand experience interviewing at top companies It is the result of hundreds of conversations with candidates It is the result of the thousands of candidate- and interviewer- contributed questions And it’s the result of seeing.

I'll show you the 5 steps to succeed in any technical interview. We'll go over what a great study plan looks like, resources to help you find jobs, and how you should conduct yourself during the interview. Please Subscribe! That is the one thing you could do that would make me happiest.

Links from the video below My Code School (Intro to Data Structures): MIT Open Courseware (Intro to Algorithms): HackerEarth and HackerRank: Programming Interview Exposed: Cracking the Coding Interview: How to Conduct a Mock Interview: Angellist: HackerNews Who's Hiring: Making a great resume: Passing the Interview: Join us in the Wizards Slack channel: And please support me on Patreon: Follow me: Twitter: Facebook: Instagram: Instagram: Signup for my newsletter for exciting updates in the field of AI.

Cracking The Coding Interview: 12 Things You Need To Know Cracking the coding interview is the holy grail of many programmers and software developers, but is cracking the coding interview really possible? Nothing, I mean nothing, terrifies more software engineers than the dreaded coding interview. Sure, Gayle McDowell, wrote an excellent book that is actually called but is it actually possible? Yes, but I don't think memorizing a bunch of programming questions is all you need to do to be successful at cracking the coding interview. Here are 12 things you need to know if you really want to stand a chance at cracking the coding interview: Remember — the coding interview is just one piece of the puzzle. You may find my course, a useful tool to fit all the pieces together. #1 How to code algorithms (really cracking the coding interview) It's a coding interview–duh.

If you want a chance at cracking the coding interview, you have to be able to code. I'm often surprised how many software engineers don't realize this simple detail. Now, writing regular day-to-day code is a bit different than writing the kind of code to implement the coding interview problems you are likely to get–which mostly consist of algorithms. You may get questions like: Write an algorithm to find an element in a linked list and move that element to the end of the list. Or you might get a question that basically asks the same thing, but disguises it in a clever word problem involving robots on an assembly line.

Regardless, you need to know how to program algorithms. But, are you born knowing how to program algorithms? Perhaps you were, but I wasn't. Instead, I had to practice. Sure, you may have learned a little bit about data structures and how to implement different kinds of algorithms in college–and you may even remember a little bit of it–but, you probably didn't do a whole lot of practice at writing bubble sort algorithms or searching binary trees. But, I wouldn't give you a problem and get you all nervous without giving you a solution, would I? No, I wouldn't.

Well, I might, but I wouldn't be that obvious about it. Anyway, here are some good resources to practice coding algorithms. Top Coder – (It's an older post of mine, so cut me some slack.). – Classic book by Jon Bentley. (I even remembered his name without having to look it up.) Chock-full of hard problems that you have to write code to solve.

Great practice and a lot of fun. If you don't like solving these problems, what are you doing being a programmer. – Even though Gayle's book is, I still have to recommend it, because it really is good and does have a lot of good problems to practice and learn from. But, make sure you don't just memorize those problems. Work them out on your own, so you can get good at doing it.

Yes, I'm talking to you!. – See, I didn't even put my course first. In this course, I basically walk you through solving a few of these algorithm problems and do something that I haven't seen anywhere else: I give you an actual process for how to learn how to solve these types of problems yourself. I also cover a bunch of other job interview tips and questions.

– If I don't include this one, I'll get a bunch of emails from people whining about how I didn't include project Euler. So, there, here it is. (That is an awkward sentence.) Anyway, this is actually a really good resource.

Plus, there are lots of examples of how all kinds of people solved these problems in all kinds of wacky ways, doing all kinds of psychedelic drugs. Ok, enough about that one. I've got, like, 11 more to cover.

Just make sure you get to the point where you feel comfortable writing some code to sort an array containing the color of hair on a cat into three lists in order of hair length, or something like that. #2 Write code WITHOUT tools Yes, Visual Studio with Resharper basically makes you a demi-god. Yes, I know you Java people, that IntelliJ and Eclipse do the same things without any plugins. Yes, I know that you Node people do it all without an IDE and can do it all with just your Sublime Text.

(Oh, and about 50 plugins that essentially make it an IDE, but we won't talk about that. Shhhh.) Anyway, IDEs and bare-bone-text-editors-with-50-million-plugins, are extremely powerful, but when you walk into a coding interview, you might just get handed a piece of chalk. (So, that means you Linux guys and gals with your VM and Emacs will need to take heed as well.) I'm not suggesting that you write your everyday production code on a chalkboard. But, you might want to at least practice sketching out some code by hand without auto-complete or typing some code into notepad if you really want to be cracking the coding interview. Do you feel me? #3 Have a portfolio You know what proves you can code more than anything else?

It seems like far too easy of an answer. But, if I am wondering if you can write code and I see your code–or something you built with code–that kinda proves it for me. Yup, this guy either randomly hit keys on his keyboard until an app magically popped out, or he can code. So, it only makes sense that someone who has hopes of cracking the coding interview would have a portfolio full of code and applications they built using code to show any prospective interviewer. What's that you say? How do you get a portfolio?

I'm glad you asked. Here are two easy ways:. Build mobile apps and have the source code ready to show. I always harp on the idea that new developers, especially, should take advantage of how easy it is to build a complete mobile application all by themselves.

Seriously, go learn Android or iOS, and build at least one or two simple mobile applications that you can show off. It's nice to be able to point to some app you built that is in an app store and then show them the code you wrote to make it. Get GitHubbing. GitHub is a wonderful place where you can put open-source code you are working on for the world to see. You can also contribute to open-source projects, which will give an excellent example of the kind of code you write and prove that you can work on a large-scale application. GitHub is an excellent portfolio for any coder.

You can also build web apps or VB6 apps to showcase your talents, but I'm going to stick with my top two choices. Now that is how you really get to cracking the coding interview. Throw down some printed out VB6 code on their desk and shout “wa-bam son!”) #4 Think out loud Interviewers are not mind-readers. They don't know what you are thinking when you are scratching your head trying to figure out how to insert a new node into a linked list. Sure, you might not get the interview question right, but you can at least let the interviewer know you are on the right track or that you aren't completely stupid, by thinking out loud while you are trying to solve the problem.

Trust me, I've been on the other end of the interview table enough times to know that there is nothing worse than someone frantically sweating, soaking through their shirt, while crushing the whiteboard marker in their hand and frantically erasing things in complete silence. It's awkward. It makes me uncomfortable. It makes you uncomfortable. Cinema raw development 2.0 for mac.

It makes the little duck I have sitting in my office that I tell all my problems to uncomfortable (and he's got a high tolerance for this shit.) So, just talk. When you are trying to solve a problem, talk through it. You do get bonus points for thinking about a problem the right way and showing your problem solving skills–even if you don't get the answer right. #5 Don't argue, blame or make excuses I really shouldn't have to say this one but, sadly I do.

Seriously, as Vince Vaughn would say: “Our little baby’s all grows up. You know what? Our little baby’s all grows up. I’m not even hungry, I couldn’t touch it. Our little boy is all grows up tonight. You know what big boy? You’re grown up.

You’re grown up! Is this a f.’ production for ya? Cuz you’re growns up and you’re growns up and you’re growns up! I’m the asshole in the bar place is that right? I’m the asshole? I’m outta here.

I’m not eatin’ anything. I wouldn’t eat here, I would never eat here anyway.” -Vince Vaughn, Swingers (1996) Ok, I didn't really need to put that long quote in there, but I've been waiting to use it, but I think you get the point. You are a big boy–or girl. Don't be a f. baby! If you don't know the answer to the interview question, don't be all like “YOU DIDN'T ASK ME IT RIGHT!” Don't blame your computer science professor for not using deodorant, so you couldn't pay attention in class. Don't make excuses like you aren't feeling well or your mommy forgot to pack your lunch today.

Man up, or put on your big girl panties–whatever the case may be. (No judgments.) Take responsibility for your own actions and if you don't know the answer, simple, say “I don't know the answer.” Or even better, say “I don't know the answer but I'll find out. You s.brain a.hole!” Ah! Just seeing if you are still paying attention. #6 Don't give up I'm so tempted to drop another Vince Vaughn quote on you right now, but I am going to resist the urge and just tell you to not throw in the towel too early. Really, at the first sign of trouble, don't just throw your hands up in the air and give up.

Try a little. Try a little more. Make them tear you from the blackboard kicking and screaming while you swear that all you need to do is just swap this one variable and your algorithm will work. (Ok, don't do that, but I think you get my point.) F.

it, you're getting Vince Vaughn after all: Trent: You know what you are? You're like a big bear with claws and with fangs Sue: big f.ing teeth, man. Trent: Yeah big f.in' teeth on ya'. And she's just like this little bunny, who's just kinda cowering in the corner. Sue: Shivering. Trent: Yeah, man just kinda you know, you got these claws and you're staring at these claws and your thinking to yourself, and with these claws you're thinking, “How am I supposed to kill this bunny, how am I supposed to kill this bunny?” Sue: And you're poking at it, you're poking at it Trent: Yeah, you're not hurting it.

You're just kinda gently batting the bunny around, you know what I mean? And the bunny's scared Mike, the bunny's scared of you, shivering. Sue: And you got these f.ing claws and these fangs Trent: And you got these f.ing claws and these fangs, man! And you're looking at your claws and you're looking at your fangs. And you're thinking to yourself, you don't know what to do, man. “I don't know how to kill the bunny.” With this you don't know how to kill the bunny, do you know what I mean?

Sue: You're like a big bear, man. Mike: So you're not just like f.ing with me? Trent: No I'm not f.ing with you. Sue: Honestly, man. Ok, so it wasn't even completely relevant, but just pretend like it was, ok? Anyway, an interviewer will respect you a lot more if you try hard. No one wants a coworker that whines about how hard something is and gives up and browses Facebook all day.

You have claws, use them. (See, what I did there?) #7 Test your code. My code is off the hook. I don't need to test it. Yes, I know your code is perfect the second you write it.

Yes, I know that angels sing and the clouds part when you place the last curly brace on the algorithm you implemented. But, you gotta make it look like you at least gave it some effort. You don't want your interviewer to reject you simply because you would create a completely unobtainable standard by which all mere mortal programmers would be judged, once you joined the company. So, pretend like your code might be capable of having errors and test through it before you tell the interviewer that you are done.

Really, I can't believe how many software engineers, who would normally test every line of code they write, completely forget to do this in an interview or think it's not important. Write a unit test to test it if you can, but if you can't, at least paper test it. (That means walk through the code with possible inputs, line-by-line.) #8 Name things clearly Another thing that seems to go out the window during the coding interview. If you want a chance at cracking the coding interview, you need to come up with better names than “banana.”. You should never name your variables after fruit Yes, someone I worked with–I won't name names–once named all the variables in their C application after names of fruits. It was exactly as amusing as it sounds. If you are in a coding interview and you write code with one-letter variable names–like I so often see in coding interviews–the interviewer is going to assume that is how you normally write the code that you put into production in real-world applications.

I know that you really name your variables wonderfully. You know you do. But, guess what? The interviewer doesn't.

It takes you like 2 extra seconds to think of and write out a clear and meaningful variable name, so do it. Do not make me pull out another irreverent Vince Vaughn quote. I've already got Wedding Crashers loaded up on IMDB.com and I am ready to go. #9 Ask for feedback You write perfect code.

We've already established that. Your variable names are perfect and make angels cry. You don't have to try and convince me, I know it. But, even with all that perfection floating around, it doesn't hurt to ask the interviewer their opinion on your code and your solution to the problem. Yes, I know they are going to say some irrelevant bull-crap, but remember what I said about making them feel important? You know that unobtainable standard of perfection that you don't want to project? Ask them for feedback.

Especially if you don't know the answer to a problem and they've timed you out. Show that you are interested in learning and that you don't just want to get the answer right, but you want to understand it. I guarantee it won't make you look stupid. #10 Don't rush It's not a race. Cracking the coding interview isn't about being super fast and not giving a crap if you get everything wrong. It's about being thoughtful, analytical, careful and accurate.

(Dammit Chrome, analytical is too a word. I'm leaving it.

Cracking Coding Interview Book In Git

You can put that little squiggly under the word all you want!) Anyway, here is the deal: No one is going to be super impressed if you whip out code super fast, but do it carelessly–even if your code is flawless. I know it seems super impressive. I know you see presenters at conferences do it–but, let me let you in on a little secret there, they use a macro. But, the big problem is, it looks careless. It looks like you just don't care and you are all about showing off instead of writing good code.

I don't know about you, but I want to work with someone who is deliberate and takes their time to make sure things are right, not some hot-shot code-jockey that slams out code and lets me deal with the bugs. So, don't be that guy. Be the guy who takes his time, tests his code and makes sure it works, before he throws it over to the interviewer and says he's done. I like that guy. #11 Practice mock interviews and take notes Again, another basic, duh, thing that seems so obvious, yet so many programmers fail to do. Your code is abysmal Before going into a coding interview, practice being interviewed. You can even set up real interviews, but I like to have interviews with my imaginary friends or long-dead historical figures.

One time Abraham Lincoln told me to write an algorithm to reverse all the words in a string while singing the national anthem. Benjamin Franklin often extols the role that virtues play in the proper naming of variables when I mock interview with him. In all seriousness though, go out and practice some mock interviews with your friends or your family.

Get comfortable answering the questions an interviewer is likely to ask you. And, when you do go to an actual interview, regardless of the outcome, take notes afterward, when the interview is still fresh in your mind. I constantly hear developers whining about how they keep getting rejected, interview after interview.

Well, guess what they say when I ask them if they did any mock interviews? And, when I ask about taking notes, so they'll know what they need to work on next time and improve? Do you know what whining without doing anything about your problem is? It's annoying! #12 Ask questions Alright, we've reached the end. I'm tired of writing, you are tired of reading what I am writing, but I've got one more point and then you can load blast this blog post all over your Twitter feed, submit it to Hacker News and My last tip, is one that isn't so obvious, because a coding interview doesn't really feel like a real work environment, but once you make the connection, I'm sure you'll see how important it is.

Let me give you a bit of an example that will illustrate what I'm about to tell you. Suppose you are at your job gathering some requirements from a customer about what you are supposed to build. Let's pretend like they are sane and you're sane.

We're all sane in this example. (Even though we know this is far from the truth in real life.) Anyway, do you ask the customer one question about what you are supposed to build and then go off to your desk to code it up? Smacks your hand with a ruler No!

No, you don't. What you do is, you ask a bunch of questions. How tall do you want the box? What is supposed to happen when the customer enters their name?

Do we need just the last name and the first name or do we need the middle name and their grandma's name as well? What color underwear are you wearing? You ask a lot of questions. You drill deeper to find out more information. So, why don't you do that in an interview. Don't just start coding the solution to a problem.

Even if you think you understand it. Ask the interviewer some questions to confirm. The point isn't to run off and code the right answer, the point is to simulate how you'd behave in a real-world environment. Just like naming things, if you don't ask clarifying questions about your assignment in a coding interview, the interviewer is likely to assume that you wouldn't ask questions in a real-world situation either. So, take your time, ask questions–make sure you understand what kind of code you are supposed to write, before you write it. #Bonus: Want to avoid a lot of this and get the job anyway?

Look, here's the deal. All of this is useful for cracking the coding interview. I sincerely hope it helps you, but I'd be doing you a big disservice if I gave you all these tips, slapped you on the back and said, “good luck kid.” I'll tell you why.

The reason is because while cracking the coding interview can be an important part of landing your dream job, it's not the only component, nor is it the most important. In fact–and you are going to find this hard to believe–you can sometimes sometimes avoid the coding interview completely if you have a good grasp of the kind of Soft Skills that can let you slip in the back door. Many times in my career I was offered a job, not because I was a crackerjack coder , but rather because I had figured out ways to build connections with interviewers at the company ahead of time and had built up a reputation online that allowed me to sometimes even bypass the interview completely. Anyway, I wrote a book called that is full of all kinds of advice on how to improve your career, get a better job, become more productive and even improve your health and finances. And it's all written specifically for software engineers, programmers, software developers, whatever you want to call yourself. Dungeon of doom chicago. If you liked this blog post– if you found it funny or at all entertaining, I'm pretty sure you'll enjoy So, Seriously, Look, it's way better than Cracking the Coding Interview, (sorry Gayle), just Ok, that's all I have to say Peace!