Cracking the Coding Interview Advice and Strategies for Software Gayle Laakmann McDowell

Cracking the Coding Interview
Advice and Strategies for Software
Engineering and PM Interviews
Gayle Laakmann McDowell
Founder / CEO, CareerCup.com
Author of The Google Resume and Cracking the Coding Interview
McDowell | CareerCup.com | UC Irvine
1.23.2012
Technical Skills
My Background
– 3 Years on Google Hiring Committee
– Interviewed 150+ candidates
• Founder of CareerCup.com
• Author
– Cracking the Coding Interview
– The Google Resume
Process
Applying
Behavioral
• Software Engineer @ GOOG, MS & Apple
McDowell | CareerCup.com
posted at:
www.technologywoman.com
Click “Speaking Engagements”
Technical Skills
Process
Applying
Behavioral
Slides Posted Online
McDowell | CareerCup.com
Technical Skills
Behavioral
Process
Applying
Evaluation
Experience
Structure
Resume
Tech Skills
Preparation
Preparation
Interview
Interview
Process
Applying
Soft Skills
McDowell | CareerCup.com
Interview Process
McDowell | CareerCup.com
Technical Skills
Big Company Evaluation (Coding)
Coding
Skills
Intelligence
Process
Applying
Behavioral
Experience
Personality
McDowell | CareerCup.com
Testing
aptitude, not
knowledge
Technical Skills
Start-Ups (Coding)
• “Hit the ground running”
Behavioral
• Entrepreneurial
Applying
– Do you know “their” technologies?
• Personality
– Have you started things?
– How much direction do you need?
Process
– Will you fit with the team?
McDowell | CareerCup.com
but…
it varies!
Technical Skills
Behavioral
•
•
•
•
•
Communication Skills
User-Focused Thinking
Passion for Technology
Analytical Skills
Technical Skills (position dependent)
Process
Applying
PMs (Microsoft) & APMs (Google)
McDowell | CareerCup.com
Technical Skills
Behavioral
Applying
Process
How You Are Judged
How did you do RELATIVE
to other candidates on
the SAME question?
It’s not about how
quickly you solved
the problem…
… it’s about how quickly
you solved it relative to
other candidates.
McDowell | CareerCup.com
Resumes & Application Process
McDowell | CareerCup.com
Technical Skills
How to Get an Interview
Applying
Behavioral
• Build something!
Don’t waste your summers!
• Make a kick-ass resume
It’s really not that hard.
Process
(So why are people so terrible at it?)
McDowell | CareerCup.com
Technical Skills
How We Review Resumes
3.
Applying
Behavioral
1.
2.
Reject
4.
Process
Pull resume out of giant stack
Spot-check: company names,
positions, projects, schools.
Skim bullets to see if you’ve
written real code.
Interview
Go to next resume & whine about
how many more you have left.
McDowell | CareerCup.com
“Glanced
at,” not read.
15 – 30
seconds
How CS Resume
Should Look
One Page Only!
Unless > 10 years exp.
A Real Resume Format
with organized columns
Short (1 – 2 line bullets)
Focus on Accomplishments
not responsibilities
GPA if at least 3.0
max (in-major, overall)
3 – 4 Projects
Courses & independent
Finished or unfinished
List of Technical Skills
Short! Cut the “fluff.”
Observe: No Objective!
Objectives / summaries
are almost always useless.
Behavioral Questions
McDowell | CareerCup.com
Technical Skills
Communication Tips
Behavioral
• Goals:
– Answer the question.
– Deliver a *good* answer.
– Communicate well.
– Nugget First
– S.A.R.: Situation, Action, Result
Process
Applying
• Strategies:
McDowell | CareerCup.com
Technical Skills
Preparing for Behavioral Qs
• Create Preparation Grid for Projects
Behavioral
OS Project
Amazon Intern.
Enjoyed
Hated
Applying
Most Challenging
Hardest Bug
Process
+ Behavioral Grid [for PM & less tech. roles]
McDowell | CareerCup.com
Technical Skills
Structure 1: Nugget First
Behavioral
• Lead with your “thesis” / nugget
– Grabs the listener’s attention
– Gives them context for where you’re going.
A: I’m most proud of the way I
re-architected the …
Process
Applying
Q: What accomplishment are you
most proud of?
McDowell | CareerCup.com
Technical Skills
Behavioral
S ituation
A ction
R esult
What was the issue?
What did you do about it?
What was the impact?
Process
Applying
Structure 2: S.A.R.
McDowell | CareerCup.com
Technical Skills
Interview Prep
McDowell | CareerCup.com
Technical Skills
How to study
• Study the basics
Behavioral
• Practice solving questions
Applying
– Complex algorithms generally unnecessary.
• Push yourself!
• Write code on paper
Process
– Don’t memorize!
– See: CtCI & CareerCup.com
McDowell | CareerCup.com
Technical Skills
Behavioral
• How to implement
• When to use (pros / cons)
Linked Lists
Stacks
Queues
Trees
Tries
Graphs
Vectors
Heaps
Hashtables
Process
Applying
Data Structures
McDowell | CareerCup.com
Technical Skills
Behavioral
• Implementation
• Space vs. Time
Complexity
Quick Sort
Merge Sort
Tree Insert / Find
Binary Search
Breadth-First
Search
Depth-First
Search
Process
Applying
Algorithms
McDowell | CareerCup.com
Technical Skills
Concepts
Threading
System Design &
Scalability
Memory
Management
Recursion
Probability +
Combinatorics
Bit Manipulation
Process
Applying
Behavioral
• Not just a concept – know how to code!
McDowell | CareerCup.com
Technical Skills
Mastering the Interview
McDowell | CareerCup.com
1. Product Design Questions
2. Estimation Questions
3. Software Engineering Questions
– Coding & Algorithms
– Object Oriented Design
– Scalability
Technical
Product Design
Estimation
Types of “Serious” Questions
McDowell | CareerCup.com
Technical
Estimation
Product Design
Product Design Questions
How would you design an
calculator for the blind?
Design an elevator for a building.
Pick a Google product.
How would you improve it?
Product Design
Estimation
Technical
Product Design Questions: Why?
•
•
•
•
Communication & Structured Thinking
Ability to understand the user
Creativity
Business instincts / skills
Technical
Estimation
Product Design
Product Design Qs: Approach
1.
2.
3.
4.
Ask questions to resolve ambiguity
Understand the user
Structure the problem
Solve piece by piece
Technical
Estimation
Product Design Qs: Example
How would you design a calculator for the blind?
Step 1: Ask Questions
• Adults? Children? Professionals?
• Where are they using it?
Product Design
– School, work, etc.
Technical
Estimation
Product Design
Product Design Qs: Example
How would you design a calculator for the blind?
Step 2: Understand the User
• What’s important to a blind child?
– Keeping up with the rest of the class
– Not feeling “different”
– Efficient input / output
• What about teachers, parents,
classmates, etc.?
Technical
Estimation
Product Design
Product Design Qs: Example
How would you design a calculator for the blind?
Step 3: Structure
• Find a structure
– Otherwise, you’re just blabbering
• One approach:
1.
2.
3.
4.
Make list of functions necessary
Discuss how to do input / output
Usability for non-blind
Summary
Technical
Product Design Qs: Example
How would you design a calculator for the blind?
Product Design
Estimation
Step 4: Solve!
Technical
Estimation
Product Design
Estimation Questions
How many tennis balls
can fit in an SUV?
How much money does Gmail make
from ads every year?
How much do New Yorkers
spend on electricity each year?
Technical
Estimation Qs: Why?
Product Design
Estimation
• Problem Solving
• Basic Quantitative Skills
Technical
Estimation Qs: How to Approach
1. Ask questions to resolve ambiguity
Product Design
Estimation
– Don’t make assumptions (yet)
2. Outline / Structure Your Approach
3. Break down the components
– Assume numbers when necessary
– State assumptions explicitly
– Round numbers to make your math easier
4. Sanity Check
– Do your numbers make sense?
Technical
Estimation
Product Design
Estimation Qs: Example
How much money does Gmail make from ads every year?
Step 1: Ambiguous Information
• Profit or revenue?
• Past year? Or average over history?
• Gmail only? Or include Google Apps?
Technical
Estimation Qs: Example
How much money does Gmail make from ads every year?
Product Design
Estimation
Step 2: Outline Your Approach
(# of users)
x
(# clicks / year)
x
( $ / click )
Technical
Estimation Qs: Example
How much money does Gmail make from ads every year?
Step 3: Break down components
Product Design
Estimation
Estimate # of Gmail users in the US
1. Assume 300 million people in the US.
–
–
Exclude 0 - 12 years old and 65 - 75 years old
 ~ 200 million
2. Assume 80% of people use email
3. 80% of those have non-work account
… and so on …
Technical
Estimation
Estimation Qs: Example
How much money does Gmail make from ads every year?
Step 4: Validate Numbers
• Could revenue be $5 billion?
• No, because…
Product Design
– Google’s annual revenue is ~$40 billion
– $16 / US citizen (not just Gmail users)
Technical
Technical Questions
1. Ask Questions!
–
Questions are more ambiguous than they appear
Estimation
2. Talk out loud
–
Show us how you think
3. Think critically
–
Does your algorithm really work? What’s the
space and time complexity?
4. Code slowly and methodically
Product Design
–
It’s not a race
5. Test your code
–
And make CAREFUL fixes.
McDowell | CareerCup.com
Technical
What does a “good coder” do?
Product Design
Estimation
• Be methodical. Don’t try to rush.
• Reasonably Bug Free
–
–
Thorough testing (and careful fixing)
Check for error conditions
• Clean coding
–
–
–
Use other functions
Good use of data structures (define own if useful)
Concise and readable
McDowell | CareerCup.com
Coding & Algorithms
Object Oriented Design
System Design
“Reverse a Linked
List”
“Design a Parking
Lot”
“Design a
Web Crawler”
Product Design
Estimation
Technical
Types of Interview Questions
McDowell | CareerCup.com
Technical
Types of Interview Questions
Coding & Algorithms
Object Oriented Design
Estimation
Pattern Matching
Simplify & Generalize
Product Design
Base Case & Build
Data Structure
Brainstorm
McDowell | CareerCup.com
System Design
Technical
Algorithm Qs: Pattern Matching
Coding & Algorithms
Estimation
Pattern Matching
Simplify & Generalize
Product Design
Base Case & Build
Data Structure
Brainstorm
Object Oriented Design
System Design
Q: Write code to reverse the order of words
in a sentence.
“dogs are cute”
“cute are dogs”
Similar to: reverse characters in a string.
“dogs are cute”
“etuc era sgod”
A: Reverse full string, then reverse each
word.
McDowell | CareerCup.com
Technical
Algorithm Qs: Simplify & Generalize
Coding & Algorithms
Estimation
Pattern Matching
Simplify & Generalize
Product Design
Base Case & Build
Data Structure
Brainstorm
Object Oriented Design
System Design
Q: Design algorithm to figure out if you can
build a ransom note (array of strings) from a
magazine (array of strings).
Simplify: what if we used characters instead
of strings?
 Build array of character frequencies.
Generalize: how we can extend answer to
words?
A: Build hashtable from word to frequency.
McDowell | CareerCup.com
Technical
Algorithm Qs: Base Case & Build
Coding & Algorithms
Estimation
Pattern Matching
Simplify & Generalize
Product Design
Base Case & Build
Data Structure
Brainstorm
Object Oriented Design
System Design
Q: Design algorithm to print subsets of set.
{a, b, c}
 {}, {a}, {b}, {c}, {a, b},
{a, c}, {b, c}, {a, b, c}
S({})
S({a})
S({a, b})
S({a, b, c})
 {}
 {}, {a}
 {}, {a}, {b}, {a, b}
?
A: Build S(n) by cloning S(n-1) and adding n
to the cloned sets.
McDowell | CareerCup.com
Technical
Algorithm Qs: Data Structure Brainstorm
Coding & Algorithms
Estimation
Pattern Matching
Simplify & Generalize
Product Design
Base Case & Build
Data Structure
Brainstorm
Object Oriented Design
System Design
Q: There are 10^10 possible phone #s.
Explain how you could efficiently implement
assignSpecificNum(num) and
assignAnyAvailableNum().
Array (sorted)? Too slow to remove num.
Linked list? Too slow to find specific num.
Hash table? Can’t iterate through free nums.
Tree? Ah-ha!
A: Store free #s in BST. Remove when taken.
McDowell | CareerCup.com
Technical
How To Solve Algorithm Questions
Coding & Algorithms
Estimation
Pattern Matching
Simplify & Generalize
Product Design
Base Case & Build
Data Structure
Brainstorm
Object Oriented Design
System Design
Compare to similar problems.
Solve first for a simplified / tweaked problem.
Solve for n = 1, and build solution for n = 2.
Try to apply data structure to solve problem.
McDowell | CareerCup.com
Technical
Object Oriented Design
Estimation
Coding & Algorithms
Object Oriented Design
System Design
Handle Ambiguity
What about the question is ambiguous?
Design the Core Objects
What are the main objects in the system?
Product Design
Analyze Relationships
How are the objects related to each other?
Investigate Actions
What are the main operations?
McDowell | CareerCup.com
Technical
Object Oriented Design
Product Design
Estimation
Coding & Algorithms
Object Oriented Design
System Design
Handle Ambiguity
Is it a single restaurant, or part of a chain?
How would you
design the data
structures and
objects for a
restaurant?
Design the Core Objects
Guest, Party, Table, Server, Host, …
Analyze Relationships
Server and Host are both Employees…
Investigate Actions
A Party is seated at a Table by a Host…
McDowell | CareerCup.com
Technical
System Design
Estimation
Coding & Algorithms
Object Oriented Design
System Design
Handle Ambiguity
What about the question is ambiguous?
Make Believe
Pretend there wasn’t so much data & solve
Product Design
Get Real
Go back to the real problem. What breaks?
Solve Problems
Solve the issues you just found.
McDowell | CareerCup.com
Technical
System Design
Product Design
Estimation
Coding & Algorithms
Object Oriented Design
System Design
Handle Ambiguity
Do the words need to be in a specific
order?
Given millions of
documents, find
all documents
which contain a
list of words.
Make Believe
Assume everything can fit on one machine.
Get Real
Must split up data across machines.
Solve Problems
Divide hash table by file or by keyword?
McDowell | CareerCup.com
Technical
Whew! All Done!
Coding & Algorithms
Object Oriented Design
System Design
Estimation
Pattern Matching
Simplify & Generalize
<Gulp> This is a lot of
stuff. Do I need to get
everything right?
Product Design
Base Case & Build
Data Structure
Brainstorm
McDowell | CareerCup.com
Technical Skills
Behavioral
Applying
Process
Evaluation is RELATIVE,
not absolute.
It’s not about how
quickly you solved
the problem…
<Gulp> This is a lot of
stuff. Do I need to get
everything right?
</Gulp>
… it’s about how quickly
you solved it relative to
other candidates.
McDowell | CareerCup.com
Behavioral
Technical Skills
Everyone makes mistakes.
Everyone!
Process
Applying
So RELAX!
Interviews are supposed to be hard!
McDowell | CareerCup.com
Final Thoughts
McDowell | CareerCup.com
Technical Skills
After Your Interview
• Follow-up with your recruiter
Applying
Behavioral
– No response != rejection
• You have no idea how well/poorly you
did.
– Seriously. I know you think you do. But you
don’t.
• Lots of randomness.
Process
– So if you fail, get up and try again.
McDowell | CareerCup.com
Technical Skills
Other Resources
Sold Today
Behavioral
Signed!
{ask to add your name too}
today
5 stars!
Applying
$15
Process
today
$30
McDowell | CareerCup.com
CareerCup.com
• Interview Videos
• iPhone App
• Resume Review
• Mock Interviews
Or, stalk me online at…
• twitter.com/gayle
• facebook.com/gayle
• technologywoman.com
• [email protected]