[INTERVIEW][Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions].pdf

(1990 KB) Pobierz
CRACKING THE
FOURTH
EDITION
INTERVIEW
150 programming interview questions and solutions
Plus:
Five proven approaches to solving tough algorithm questions
Ten mistakes candidates make -- and how to avoid them
Steps to prepare for behavioral and technical questions
Interviewer war stories: a view from the interviewer’s side
CODING
GAYLE LAAKMANN
Founder and CEO, CareerCup.com
Table of Contents
Foreword
Introduction
Behind the Scenes
The Microsoft Interview
The Amazon Interview
The Google Interview
The Apple Interview
The Yahoo Interview
Interview War Stories
Before the Interview
Resume Advice
Behavioral Preparation
Technical Preparation
The Interview and Beyond
Handling Behavioral Questions
Handling Technical Questions
Five Algorithm Approaches
The Offer and Beyond
Top Ten Mistakes Candidates Make
Frequently Asked Questions
Interview Questions
Data Structures
Chapter 1 | Arrays and Strings
Chapter 2 | Linked Lists
Chapter 3 | Stacks and Queues
Chapter 4 | Trees and Graphs
Concepts and Algorithms
Chapter 5 | Bit Manipulation
Chapter 6 | Brain Teasers
4
5
7
8
9
10
11
12
13
20
21
23
25
28
29
31
34
37
39
41
44
46
47
49
51
53
56
57
59
1
Cracking the Coding Interview
Table of Contents
Chapter 7 | Object Oriented Design
Chapter 8 | Recursion
Chapter 9 | Sorting and Searching
Chapter 10 | Mathematical
Chapter 11 | Testing
Chapter 12 | System Design and Memory Limits
Knowledge Based
Chapter 13 | C++
Chapter 14 | Java
Chapter 15 | Databases
Chapter 16 | Low Level
Chapter 17 | Networking
Chapter 18 | Threads and Locks
Additional Review Problems
Chapter 19 | Moderate
Chapter 20 | Hard
Solutions
Index
Mock Interviews
About the Author
61
63
65
67
69
71
74
75
77
79
81
83
85
88
89
91
94
301
303
304
CareerCup com
2
Foreword
Dear Readers,
Welcome to the 4th edition of
Cracking the Coding Interview
This volume updates the 3rd
edition with new content and refreshed information Be sure to check out our website, www
careercup com, to connect with other candidates and to discover new resources
For those of you new to technical interviews, the process can seem overwhelming Inter-
viewers throw questions at you, expect you to whip up brilliant algorithms on the spot, and
then ask you to write beautiful code on a whiteboard Luckily, everyone else is in the same
boat, and you’re already working hard to prepare Good job!
As you get ready for your interviews, consider these suggestions:
»
Write Code on Paper:
Most interviewers won’t give you a computer and will instead
expect you to write code on a whiteboard or on paper To simulate this environment, try
answering interview problems by writing code on paper first, and then typing them into
a computer as-is Whiteboard / paper coding is a special skill, which can be mastered
with constant practice
Know Your Resume:
While technical skills are extremely important, that’s no reason to
neglect your own resume Make sure to prepare yourself to give a quick summary of any
project or job you were involved with, and to discuss the hardest and most interesting
problems you encountered along the day
Don’t Memorize Solutions:
While this book offers a representative sample of interview
questions, there are still thousands of interview questions out there Memorizing solu-
tions is not a great use of your time Rather, use this book to explore approaches to
problems, to learn new concepts, and to practice your skills
Talk Out Loud:
Interviewers want to understand how you think and approach prob-
lems, so talk out loud while you’re solving problems Let the interviewer see how you’re
tackling the problem, and they just might guide you as well
»
»
»
And remember -- interviews are hard!
In my years of interviewing at Google, I saw some
interviewers ask “easy” questions while others ask harder questions But you know what?
Getting the easy questions doesn’t make it any easier to get the offer Receiving an offer
is not about solving questions flawlessly (very few candidates do!), but rather, it is about
answering questions
better than other candidates
So don’t stress out when you get a tricky
question - everyone else probably thought it was hard too!
I'm excited for you and for the skills you are going to develop Thorough preparation will give
you a wide range of technical and communication skills It will be well-worth it no matter
where the effort takes you!
Study hard, practice, and good luck!
Gayle Laakmann
CareerCup com
4
Introduction
Something’s Wrong
We walked out of the hiring meeting frustrated, again Of the ten “passable” candidates we
reviewed that day, none would receive offers Were we being too harsh, we wondered?
I, in particular, was disappointed We had rejected one of
my
candidates A former student
One who I had referred He had a 3 73 GPA from the University of Washington, one of the
best computer science schools in the world, and had done extensive work on open source
projects He was energetic He was creative He worked hard He was sharp He was a true
geek, in all the best ways
But, I had to agree with the rest of the committee: the data wasn’t there Even if my emphatic
recommendation would sway them to reconsider, he would surely get rejected in the later
stages of the hiring process There were just too many red flags
Though the interviewers generally believed that he was quite intelligent, he had struggled
to develop good algorithms Most successful candidates could fly through the first ques-
tion, which was a twist on a well known problem, but he struggled to develop his algorithm
When he came up with one, he failed to consider solutions that optimized for other scenar-
ios Finally, when he began coding, he flew through the code with an initial solution, but it
was riddled with mistakes that he then failed to catch Though he wasn’t the worst candidate
we'd seen by any measure, he was far from meeting “the bar ” Rejected
When he asked for feedback over the phone a couple of weeks later, I struggled with what to
tell him Be smarter? No, I knew he was brilliant Be a better coder? No, his skills were on-par
with some of the best I'd seen
Like many motivated candidates, he had prepared extensively He had read K&R’s classic C
book and he'd reviewed CLRS' famous algorithms textbook He could describe in detail the
myriad of ways of balancing a tree, and he could do things in C that no sane programmer
should ever want to do
I had to tell him the unfortunate truth: those books aren’t enough Academic books prepare
you for fancy research, but they’re not going to help you much in an interview Why? I'll give
you a hint: your interviewers haven’t seen Red-Black Trees since
they
were in school either
To crack the coding interview, you need to prepare with
real
interview questions You must
practice on
real
problems, and learn their patterns
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
so many interview questions from so many firms Enclosed in this book are 150 of the best
interview questions, selected from thousands of potential problems
5
Cracking the Coding Interview
Zgłoś jeśli naruszono regulamin