Cracking the Coding Interview: 189 Programming Questions and Solutions

Author: Gayle Laakmann McDowell
4.6
All Reddit 123
This Year Reddit 55
This Month Stack Overflow 1

Comments

by anonymous   2019-01-13

As the question already states that the left and right input arrays are sorted, this gives you a hint that you should be able to solve the problem without requiring a data structure other than an array for the output.

In a real interview, it is likely that the interviewer will ask you to talk through your thought process while you are coding the solution. They may state that they want the solution implemented with certain constraints. It is very important to make sure that the problem is well defined before you start your coding. Ask as many questions as you can think of to constrain the problem as much as possible before starting.

When you are done implementing your solution, you could mention the time and space complexity of your implementation and suggest an alternative, more efficient solution.

For example, when describing your implementation you could talk about the following:

  • There is overhead when creating the queues
  • The big O notation / time and space complexity of your solution
  • You are unnecessarily iterating over every element of the left and right input array to create the queues before you do any merging
  • etc...

These types of interview questions are common when applying for positions at companies like Google, Microsoft, Amazon, and some tech startups. To prepare for such questions, I recommend you work through problems in books such as Cracking the Coding Interview. The book covers how to approach such problems, and the interview process for these kinds of companies.

by Wonderful_Safety   2019-01-13

leetcode.com

hackerrank.com

>Best seller in Hacking and in Computer Security & Encryption

https://toptalkedbooks.com/amzn/0984782850

by yiliu   2019-01-13

Well, it was my fear too. When I was getting close to graduation, I was sure nobody would be interested. Then I got an interview, and then got a job, and then I was away.

Generally, at least in my experience, it's not hard to get interviews (or at least phone screens) because companies are all looking for talent and a phone screen is pretty low-cost for the company. If you're worried, warm up with some interview questions (from this kind of book for example). If you can get an interview, and if your interview goes well...well, that's all it takes.

by cool_anna   2019-01-13

Depends on the companies you're applying for. For the top 20-30 tech companies in the US ( in terms of revenue/popularity etc.), familiarity with algos and DS is must.

However, the difficulty of questions is dependent on how good a company is.

I would suggest Cracking the coding interview and leetcode are really very useful to get into top tech companies

by mindcrime   2018-11-17
If it were me, I'd probably consult Cracking The Coding Interview[1], and the Robert Sedgewick Algorithms in C++ [2][3] books. That and maybe spend some time practicing on Leetcode, Hacker Rank, Project Euler, etc. Skiena's Algorithm Design Manual[4] could also be good.

[1]: https://www.amazon.com/Cracking-Coding-Interview-Programming...

[2]: https://www.amazon.com/Algorithms-Parts-1-4-Fundamentals-Str...

[3]: https://www.amazon.com/Algorithms-Part-Graph-3rd-Pt-5/dp/020...

[4]: https://www.amazon.com/Algorithm-Design-Manual-Steven-Skiena...

by Endyd   2018-11-10

On my commutes (I drive 25 min), I have been mostly listening to Coding Blocks podcasts OR thinking about the problem I have been working on most recently and audio recording my thoughts.

When I am not able to listen to podcasts, sometimes I have looked at "Cracking the Coding Interview" book before hand and getting a problem in my head to work through while I sit/walk/drive/eat/etc.

Hope you find a great way to spend your commute!

by qspec02   2018-11-10

Cracking the Coding Interview

Really worth picking up.

by o--_--o-   2018-11-10

hi get yourself a copy of this https://toptalkedbooks.com/amzn/0984782850

have a look at this https://www.pramp.com/#howitworks

watch a few mock interviews on youtube attend meetups join irishtechcommunity and have a look at the jobs section

by yihwan   2018-11-10

It sounds like you have at least an intro into some fundamentals of computer science, which is great. I'd continue building on those and studying data structures, algorithms, etc. to make sure these skills stay sharp.

Cracking the Coding Interview is the typically recommended go-to to cram for interviews, but it sounds like you have the background to fully understand a lot of the concepts discussed. Languages don't really matter - choose whatever you're most comfortable with. Python is a great choice.

That by itself should but you in the running for a lot of software jobs. If you want to differentiate yourself further from recent CS grads, you might to shift from "fundamentals" to "tooling", i.e. actually building things with what you know. Clone a website you like, go through Wes' JavaScript30 if you're interested in front-end, etc. Having a nice portfolio of projects doesn't hurt.

by valbaca   2018-11-10

I'd recommend stepping away from leetcode and the other sites for a bit. I think they're useful if you need the practice in typing up the algorithms in code when you have the algorithms pretty well memorized.

I would HIGHLY recommend "Cracking the Coding Interview" https://toptalkedbooks.com/amzn/0984782850

There are also a few good YouTube videos but I don't have links handy. I will say there's a lot of garbage out there too, so skip through them liberally.

Remember the interview process is a total game. I interview candidates and even we know it's all a sorry game. But we have to check the stupid boxes because no one has come up with a better way to weed out people who can't code a for-loop.

Your ability to pass interviews is not directly correlated to your ability to actually deliver software in the real world. Interviews often don't touch on design or real world tradeoffs or continuous integration or how to manage a large project or so many of the other aspects of software engineering. Instead it comes down to rote memorization of solved algorithms and stupid array problems that never represent an actual problem someone has actually needed to solve.

In an interview: let's spend half an hour writing quicksort.

In real life: can you think of any language written that doesn't have a sort function in the standard lib?

I know you know this but I hope that this has helped.

Good luck.

by ShadowWebDeveloper   2018-11-10

Specifically for this interview, I rocked CTCI , Leetcode, and a bunch of GeeksForGeeks and YouTube videos. All of this proved unnecessary as the coding question was way easier than anything I studied. If you are interviewing for SWE, though, totally worthwhile.

My routine was that my wife and kid were out of the house over the last week when I got home so I could study. It worked decently well.

Ask clarifying questions where appropriate, especially if anything about the input is unclear. Handle edge cases, like empty arrays or extreme inputs. If you can't come up with an optimized solution right away, talk through the brute force solution; even if you don't get a hint from the interviewer, you might get some insight just by talking it through yourself (i.e. rubber duck debugging). Once you do get code up, do the same thing and step through your code with an input or two. Almost every time I've done this, I've found something I missed while coding.

by glowcap   2018-11-10

One book that really helped me get past the "intermediate" level was Advanced Swift. It goes into quite a bit of detail on really useful topics that YT and Udemy courses seems to skip over in favor of quick results.

When it comes to CS concepts, I only really needed them for interviews. So I used Cracking the Coding Interview . It helped me focus on the concepts I needed to get hired (which is really all I cared about). If you're looking for something more, I'd recommend edX's Algorithms and Data Structures course. I'm not sure if their certificates are worth anything in the real world, but the content definitely has value.

Good luck on your continued learning!

by firecopy   2018-11-10

> Big O notation with examples

Gayle Mcdowell teaches big O notation with examples, in their book Cracking the Coding Interview (6th Edition) (I would definitely recommend the book, if you are studying programming for a career).

To give a brief explanation: O, "big O", describes an upper bound on time. (pg. 39 of the book)

Here is a simple explanation that explains big O: https://np.reddit.com/r/learnprogramming/comments/370908/a_simple_introduction_to_big_o_notation/

Here is an extensive explanation that explains big O: https://stackoverflow.com/questions/487258/what-is-a-plain-english-explanation-of-big-o-notation


Would also recommend checking out Wikipedia to understand linked lists and hashmaps, as the site gives good visual examples.

https://en.wikipedia.org/wiki/Linked_list

https://en.wikipedia.org/wiki/Hash_table

by Qgsr   2018-11-10

Cracking the Coding Interview es la mejor inversión.

Al menos, lee que es Big-O, stack vs. heap, SOLID.

by konglongjiqiche   2018-11-10

Probably late to the game here, but if you have experience in programming you may not need to have a degree at all.

(This is anecdotal, but it is possible) You have to start small (I started with a shady craigslist position for minimum wage, no benefits), but eventually you gain enough know how to back up your linked in profile, get contacted by recruiters, and talk your way through an interview (I am now at fortune 50 company). It basically requires a lot of time completing side projects to learn new technologies. In my interviews I have NEVER been asked about my education. If you get to the point where you know this book backwards and forwards, wait for recruiters to tell you about a company that is desperate for manpower and you are in.

by nonanonoymous   2018-11-10

Someone that hires first years here [1]:

Resumes

I can only speak from the perspective of a smaller company, but I have several suggestions, some of which may be more applicable if you're going to apply to somewhere with less than 100 employees:

  1. A good resume is a must, this is a template that I recommend, keep it one page or less Make sure you get someone else to proof read, because it's a HUGE ding to your 'getting an interview' score if you have obvious typos in your resume.

  2. Some things I look for are open source contributions (github links are very valuable), even if they are just documentation changes. [2]

  3. Also, make sure you include your full (legal) name, phone number, email, and mailing address. Some people don't do this and I probably won't bother emailing you to ask you for those details if you don't include them.

  4. Even if you don't have any personal projects, have taken CSC240, CSC236 or CSC207 and having >80 usually means that you'll at least get an interview as a first year, but larger companies probably won't know the significance of having taken 240.

    • If you want an internship at big-4, you will probably need to talk to an on-campus recruiter at somewhere like YNCF, or have an internal reference. I don't know anyone that even got an interview as a first year except for within those means.
  5. If you've placed in a hackathon or have interesting (or challenging, and well put together) personal projects, that's also good enough to at least land an interview at my company.

Cover letters

Some companies will care about cover letters -- I personally count it as a negative if you include a cover letter that is obviously templated:

Dear hiring manager, I see you are doing [some random thing copied from our website] and I am myself very passionate about [that thing]...

If you are actually reaching out specifically to join my company because you know someone else that's worked here, or you've used our product and want to work with us for that reason, a cover letter is probably appropriate.

Interviewing

Interview in as many places as possible. There are really only two things you should be focusing on as a first year: Cracking the Code Interview, and not being too nervous.

Seriously. Buy cracking the code interview [3], and spend a week or so solving problems and learning memoization / pointer manipulation / dynamic programming. You'll be SO much better off.

I find that if you think of every interview as "interview practice for when it matters in later years" you will not be so nervous as a first year. Expect to not know the answers to some questions, and just explain what you are thinking to get "part marks." Freezing up looks much worse than going down the wrong path with confidence.

References

[1] I'm CEO of ParseHub -- you can contact me at colin@parsehub.com

[2] I also do optional lectures for CSC207 on Fridays noon-1PM @ BA1200, one of which will be on how to make open source contributions. Feel free to email me if you want to come.

[3] It's available on amazon

by zdwolfe   2018-11-10

If you have access to a library or want to buy it, I thought the beginning chapters of Cracking the Coding Interview did a good job of describing what I've experienced is the typical application/interview/hiring decision/acceptance process.

> When should I send out job apps?

When you're confident that you're ready to interview at 1-2 weeks notice. I shot myself in the foot by applying before I had practiced interview questions or written my resume.

> When can I expect to receive any finalized offers?

I've interviewed 8-10 times in the last few years, and I've never waited more than 2 weeks to hear a yes/no. After that, it can be another week or two until you get an offer letter. Don't be afraid to follow up after a week if you haven't gotten an answer.

> When can I expect to begin employment?

That depends, but it's not uncommon to begin a few months after you get an offer. Big companies are often more flexible about start date. When I got my first job of out college, I interviewed late August, got an offer letter early September, graduated in December, and didn't start until the following March.

Hope that helps.

by vidarc   2018-03-19

Clean Code and Cracking the Code Interview

I'm sure everyone has their opinions on those two books, but I think they'll both give you a lot of good direction. Clean Code is actually in Java, while Cracking the Code Interview is more generalized. It's been awhile since I read it, but I think it did have some Java examples.

by bonekeeper   2018-03-19

I looked at the FreeCodeCamp curriculum, it looks good for an entry level javascript developer, so since you already started it, you might as well finish it (since, like I said, everybody implicitly expects you to know at least one of python/js/perl as well as HTML+CSS).

2 hours per day is a bit too little IMO - but I understand that it's hard to find time when you have a demanding job and a family that needs time and attention. Just study as much as you can, 2h being the mininum (do keep in mind that CS students, your competition, will be studying at least 8h/day for at least 4 years with tons of homework and more advanced material). So you should probably focus on studying more in the weekends (just typing and thinking about this, I'm actually lucky I started when I was a kid, with all my bills paid for!)

Anyways. You should focus on getting a job first - do keep doing the FreeCodeCamp, as many hours in the day and weekends as you can. Explain to your significant other, if you haven't already done so, your plan - that you're studying hard to upgrade your career, that it might take some time away from them but it will pay off in the long run, etc. Ideally you should be studying at least 4h/day, so try to keep close to that, study more on weekends if necessary. Check this guy for reference on his plan and what he's studying (and note that he's studying full-time - a luxury, I know, but just to put your 2h/day into perspective). This guide is helpful too. Note that you don't need to know all that to get an entry-level development job, but keep that plan in mind for the long run (as you progress your career).

Once you finish the FreeCodeCamp, or even before (I would say, once you finish "Basic Algorithm Scripting"), try doing some local interviews if you can do it without jeopardizing your current job just to get a feel of how interviews work. You won't be trying to get a job (but hey, if you do, awesome), this is just to get your feet wet on interviewing (which is a skill in itself). Since you're not shooting to get a job right now, you won't be as nervous, which is the state of mind you want to be in. If you're relaxed you can talk better, think better, make jokes, be more presentable, which is great - this will put you in the right mood for your future interviews. Try finding people online that can do mock interviews with you in the area you will be focusing on (web/javascript/frontend initially).

Once you're past the basic HTML/CSS part and you start studying JavaScript, I suggest you look into Python as well at the same time. It is a very simple language, quick to learn, and will double your opportunities for employment. As you study both at the same time, you might notice that you like one or the other better - if that happens, focus more on the one you like better, this will accelerate your learning and get you ready for a job faster in your chosen language.

At one point you'll finish HTML/CSS and JavaScript+Python (finish as in be comfortable with them - you'll see that you'll still learn new things as years go by, it will take a few years for you to "master" them). After you're comfortable with JavaScript and Python (and hopefully gainfully employed in development), start studying that book (where you'll learn a GREAT deal about many important things, it will be a dense read, and you will come out of it knowing assembly and C) and then you can focus on algorithms and exercising your thinking with algorithmic puzzles and how computer networks work, operating systems and everything that is generally on this list.

Then after studying all that and with 2-4 years of experience under your belt (and still studying 4h/day), you can start thinking about the next level in your career and preparing for it (larger companies, mid to senior positions, etc) - add a couple more years of experience and you'll be ready to interview for large Valley companies (Google, Apple, FB, etc).

If you plan to self-study all the way through and never join an University, you can look into full-fledged CS courses online and follow that to get a complete theoretical background on CS (that all your colleagues will eventually have and expect of you, at some point in the future).

by Fofox   2018-03-19

En parlant d'entretien tech, je vous recommande ce livre : https://toptalkedbooks.com/amzn/0984782850

Il convient aussi bien à un chercheur d'emploi qu'a un recruteur en mal de questions.