SlideShare una empresa de Scribd logo
1 de 81
GayleL.McDowell | Founder/ CEO
gayle in/gaylemcdgayle
Cracking the Facebook
Coding Interview
I <3 Facebook!
CareerCup
Why am I here?
00
gayle in/gaylemcdgayleGayle Laakmann McDowell 3
Why wouldFacebookprepyou?!?
Be more
comfortable
Be more prepared
Take out
the mystery
Avoid common
mistakes
gayle in/gaylemcdgayleGayle Laakmann McDowell 4
Hi! I’m Gayle LaakmannMcDowell
Author Interview Coach Interview Consulting
<dev> </dev>
(CS) (MBA)
Gayle Laakmann McDowell 5gayle in/gaylemcdgayle
Yes! Slidesare online!
Gayle.com
 Click “Events”
 Ctrl-F for “Facebook”
What to Expect
gayle in/gaylemcdgayleGayle Laakmann McDowell 7
A Typical**Process(**notuniversal!Askyourrecruiter)
Phone Onsite HiringCommittee & Decision
½ Behavioral
½ Algo / Coding
Design
Algo / Coding
Algo / Coding
Algo / Coding
gayle in/gaylemcdgayle 8
z
Gayle Laakmann McDowell
Typical
Coding
Interview
5 Minutes
Questions FORInterviewer
35 Minutes
Question #1 Question#2
5 Minutes
Prior Experience
gayle in/gaylemcdgayle 9
z
Gayle Laakmann McDowell
Typical
Design
Interview
5 Minutes
Questions FORInterviewer
35 Minutes
Question#1
5 Minutes
Prior Experience
Behavioral
Questions
The soft squishy stuff.
02
gayle in/gaylemcdgayleGayle Laakmann McDowell 11
The Pitch /Resume Walk-Through
• Showsof success
• Prompt the
interviewer
• Hobbies
I’masoftwareengineerat...
Mybackground’sinCS.
IstudiedatUPennandthen…
Atmycurrentcompany,I…
OutsideofworkI…
Gayle Laakmann McDowell 12gayle in/gaylemcdgayle
Your Past Work
3+ Projects
 Hard / cool
 You werecentral
 Technical depth
All Past Work
 TECHNICAL:Challenges,
architecture, tradeoffs,
successes, motivations
 SOFT:Teamwork, leadership,
conflicts, etc
What did YOU do?
What would you do differently?
gayle in/gaylemcdgayle 13
z
Gayle Laakmann McDowell
What
about
YOU?
Be PASSIONATE
Be KNOWLEDGEABLE
Be a GOOD TEAMMATE
Design Questions
Big, meaty problems
03
gayle in/gaylemcdgayle 15
z
Gayle Laakmann McDowell
How
To
Approach
W
W
Y
D
A
W
hat
ould
ou
o
t
ork
gayle in/gaylemcdgayle 16
z
Gayle Laakmann McDowell
How
To
Approach
S
K
I
R
cope
eycomponents
dentify issues
epair
gayle in/gaylemcdgayle 17
z
Gayle Laakmann McDowell
How
To
Approach
① Scope the Problem
 Askquestions
 Make appropriateassumptions
② Define Key Components
 Can besomewhatnaïve
③ Identify Issues
 Bottlenecks,tradeoffs
④ Repair & Redesign
Breadth-first,notdepth-first
Gayle Laakmann McDowell 18gayle in/gaylemcdgayle
ExampleQuestion
Gayle Laakmann McDowell 19gayle in/gaylemcdgayle
Design sketch
Frontend
Backend
Data store
logger
Gayle Laakmann McDowell 20gayle in/gaylemcdgayle
Collaborativediscussionthat you’re driving!
DRIVE
 Leadtheprocess
 Be openaboutissues
TEAMWORK
 Be opentofeedback
 Tweak asnecessary
Usethewhiteboard!
gayle in/gaylemcdgayle 21
z
Gayle Laakmann McDowell
How
To
Prepare
Read about design of major companies
 THINK, don’t memorize!
Know key concepts
 Tasks, sharding, caches.
 Web stack, REST, etc
Practice back-of-the-envelope
calculations
Algorithm
Questions
Things that make you think
04
Gayle Laakmann McDowell 23gayle in/gaylemcdgayle
Why?
Analytical skills
How you think
Make tradeoffs
Pushthrough hard
problems
Communication
Strong CS fundamentals
gayle in/gaylemcdgayleGayle Laakmann McDowell 24
Essential Knowledge
Data Structures Algorithms Concepts
ArrayLists Merge Sort BigO Time
Hash Tables QuickSort BigO Space
Trees(+Tries) & Graphs Breadth-FirstSearch Recursion
LinkedLists Depth-FirstSearch Memoization/ Dynamic
Programming
Stacks/ Queues BinarySearch
Heaps
gayle in/gaylemcdgayleGayle Laakmann McDowell 25
Preparation
MASTER Big O
ImplementDS/Algorithms
Practicewith interview questions
Code on paper/whiteboard
Mock interviews
PUSHYOURSELF!
A Crash Course in Big O
Just getting your feet wet
gayle in/gaylemcdgayleGayle Laakmann McDowell 27
Basicfor loop
Print0 throughN
Runtime?
 O(N)
gayle in/gaylemcdgayleGayle Laakmann McDowell 28
Two loops
Printevens, thenodds
Runtime?O(N)
gayle in/gaylemcdgayleGayle Laakmann McDowell 29
Basicfor loop
Printpairs from two arrays
Runtime?
 O(A*B)
gayle in/gaylemcdgayleGayle Laakmann McDowell 30
Basicfor loop
Printordered pairs
Runtime?
 O(N2)
j : 0  N
i:0N
x x x x x x
x x x x x
x x x x
x x x
x x
x
gayle in/gaylemcdgayleGayle Laakmann McDowell 31
Okay now thingsare getting tougher!
gayle in/gaylemcdgayleGayle Laakmann McDowell 32
Okay now thingsare getting tougher!
Step 1: O(P)
 P = numberof people
Step 2: O(P * Y)
 Y = max life span
Step 3: O(L)
 L = last death year
O(P + P * Y + L)  O(P * Y + L)
gayle in/gaylemcdgayleGayle Laakmann McDowell 33
Validate
Validate
Runtime?
 undefined
gayle in/gaylemcdgayleGayle Laakmann McDowell 34
Fibonacci
Runtime?
Eeek. Recursion?
gayle in/gaylemcdgayleGayle Laakmann McDowell 35
Fibonacci
Eeek. Recursion?
• Height of N
• Each level doubles # nodes
•  O(2N) time ***
•  O(N) space
Actuallyslightlylessforcomplexmathreasons.
gayle in/gaylemcdgayleGayle Laakmann McDowell 36
Fibonacci, part 2
Runtime?
Eeek. Recursion?
• Height of N
• Each level has <=2nodes
•  O(N) time
•  O(N) space
gayle in/gaylemcdgayleGayle Laakmann McDowell 37
Reminders
Drop constants
Don’t drop non-constants
Differentvariables
Avoid ‘n’
Add vs. Multiply
Recursion call tree
Solving Algorithms
How to… attempt to solve a hard problem
gayle in/gaylemcdgayle 39
z
Gayle Laakmann McDowell
What
is NOT
expected
To know the answers
To solve immediately
To code perfectly
(It’snice.Itjustdoesn’t
happen*.)
*Okayfine.Ithappenedonce,in2000+hiringpackets.
gayle in/gaylemcdgayle 40
z
Gayle Laakmann McDowell
What
IS
expected
Be excitedabout hard problems
Drive!
 Keep trying when stuck
 More than just “correct”
Pay attention to me!
Write real code
Showmehowyouthink!
gayle in/gaylemcdgayle 41
z
Gayle Laakmann McDowell
How
To
Approach
CrackingTheCodingInterview.com“Resources”
gayle in/gaylemcdgayle 42Gayle Laakmann McDowell
step
Listen (for clues)
Gayle Laakmann McDowell 43gayle in/gaylemcdgayle
What’s the clue?
Anagram server
 Ex: rates ->aster, stare, taser, tears
Clue:why is it on a server?
Key(sorted string) Value (list of words)
aerst rates, aster, stare, taser, tears,
dgo dog, god
acll call
… …
gayle in/gaylemcdgayle 44Gayle Laakmann McDowell
step
Draw an Example
INTERSECTION SIZE: Find #
elementsin common between
two sorted, distinct arrays:
gayle in/gaylemcdgayleGayle Laakmann McDowell 45
Ex:Intersection ofTwo Sorted Arrays
Most people draw somethinglike this:
[1, 12, 15, 19]
[2, 12, 13, 20]
 Toosmall
 Toospecial-case-y
• same size, one commonelement, same index
gayle in/gaylemcdgayleGayle Laakmann McDowell 46
Ex:Intersection ofTwo Sorted Arrays
Better:
[1, 12, 15, 19, 20, 21]
[2, 15, 17, 19, 21, 25, 27]
 Big
 No specialcases
gayle in/gaylemcdgayle 47Gayle Laakmann McDowell
step
Draw an Example
Big Enough
General Purpose
+
gayle in/gaylemcdgayle 48Gayle Laakmann McDowell
step
Brute Force / Naive
Stupid&terribleisokay!
gayle in/gaylemcdgayle 49Gayle Laakmann McDowell
step
Optimize
Walk through brute
force
Look for optimizations
Gayle Laakmann McDowell 50gayle in/gaylemcdgayle
Techniquesto Develop Algorithms
BUD
Space and Time
Do It Yourself
Recursion
Gayle Laakmann McDowell 51gayle in/gaylemcdgayle
(A) Look for BUD
Bottlenecks
Unnecessary work
Duplicated work
Gayle Laakmann McDowell 52gayle in/gaylemcdgayle
What’s the bottleneck?
 Ex: countingthe intersection
[1, 12, 15, 19, 20, 21]
[2, 15, 17, 19, 21, 25, 27]
 Bottleneck:searching
B
Gayle Laakmann McDowell 53gayle in/gaylemcdgayle
What’s unnecessary?
 Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000
 Unnecessary: looking for d
U
Gayle Laakmann McDowell 54gayle in/gaylemcdgayle
What’s unnecessary?
 Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000
 Unnecessary: looking for d
U
Gayle Laakmann McDowell 55gayle in/gaylemcdgayle
What’s duplicated?
 Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000
 Duplicated: c, d pairs
D
Gayle Laakmann McDowell 56gayle in/gaylemcdgayle
What’s duplicated?
 Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000
 Duplicated: c, d pairs
D
c d c3 + d3
… … …
4 31 29855
4 32 32832
4 33 36001
… … …
5 59 205504
5 60 216125
5 61 227106
… … …
Gayle Laakmann McDowell 57gayle in/gaylemcdgayle
What’s duplicated?
 Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000
 Duplicated: c, d pairs
D
c3 + d3 (c, d)
… …
29855 (4, 31)
32832 (4, 32),(18, 30)
36001 (4, 33)
… …
205504 (5, 59)
216125 (5, 60),(45, 50)
227106 (5, 61)
… …
Gayle Laakmann McDowell 58gayle in/gaylemcdgayle
What’s duplicated?
 Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000
D
Gayle Laakmann McDowell 59gayle in/gaylemcdgayle
What’s duplicated?
 Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000
D
Gayle Laakmann McDowell 60gayle in/gaylemcdgayle
(B)Space/TimeTradeoffs
Hashtables & other datastructures
Precomputing
Gayle Laakmann McDowell 61gayle in/gaylemcdgayle
(C)Do it yourself
Findpermutationsof swithinb
gayle in/gaylemcdgayleGayle Laakmann McDowell 62
find abbcd in
b a b c d b a e f d b b a c b d d f a e
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Gayle Laakmann McDowell 63gayle in/gaylemcdgayle
(C)Do it yourself
Findpermutationsof swithinb
 s = abbcd
 b =
Findthem!
 … now how didyou actuallydoit?
b a b c d b a e f d b b a c b d d f a e
Gayle Laakmann McDowell 64gayle in/gaylemcdgayle
(D)Recursion
 Use, but don’t cling to, recursion
“instinct”
 Trybottom-up
 “Backtracking”
 Draw call-tree
 Derive runtime
 Find repeated subproblems
 Subsets of a set
 {} {}
 {a}{},{a}
 {a,b} {},{a},{b},{a,b}
 {a,b, c} …
 Subsets of {S1…Sn-1} +Sn to each
Gayle Laakmann McDowell 65gayle in/gaylemcdgayle
Techniquesto Develop Algorithms
BUD
Space and Time
Do It Yourself
Recursion
gayle in/gaylemcdgayle 66Gayle Laakmann McDowell
step
Walk Through
Know the variables
andwhen they change
gayle in/gaylemcdgayle 67Gayle Laakmann McDowell
step
Write Beautiful Code
Gayle Laakmann McDowell 68gayle in/gaylemcdgayle
How toWrite WhiteboardCode
Write straight
Top-leftcorner
Use arrows if needed
Error cases
Good style
Modularize (upfront!)
Languagechoiceisuptoyou!
Gayle Laakmann McDowell 69gayle in/gaylemcdgayle
Error Cases
Good to check errors / boundaries!
But consider the time…
gayle in/gaylemcdgayleGayle Laakmann McDowell 70
Good Style
Spacing, line breaks, variable names
Gayle Laakmann McDowell 71gayle in/gaylemcdgayle
Language Choice
Java, Objective C, etc:Abbreviate
Python, Ruby, JS,etc: Carefulwithbuilt-infunctions
gayle in/gaylemcdgayleGayle Laakmann McDowell 72
Modularization
Gayle Laakmann McDowell 73gayle in/gaylemcdgayle
Modularize(Upfront!)
I’ve learned
nothing.
gayle in/gaylemcdgayle 74Gayle Laakmann McDowell
step
Testing
FIRST Analyze
 What’s it doing? Why?
 Anything that looks weird?
 Errorhot spots
THEN use test cases
 Small test cases
 Edge cases
 Biggertest cases
BUT…
 Test code, notalgorithm
 Think as you test
 Think before you fix
Find permutationsof s withinb:
s = abbc
b = babcabbacaabcbabcacbb
for (i = 0; i < b.len – s.len; i++) {
if (isPerm(s, b.subs(i, s.len)) …
}
gayle in/gaylemcdgayle 75
z
Gayle Laakmann McDowell
How
To
Approach
CrackingTheCodingInterview.com“Resources”
Questions for Your
Interviewer
What do you want to know?
05
Gayle Laakmann McDowell 77gayle in/gaylemcdgayle
Prepare some questions
What’s made you
happy / unhappy?
What are your goals?
Culture& work style
Career paths
Technology
Interviewer’s
experience
Final Thoughts
And questions
06
gayle in/gaylemcdgayle 79
z
Gayle Laakmann McDowell
It’s done
for a
reason!
Be agreat teammate.
Be a great engineer.
Gayle Laakmann McDowell 80gayle in/gaylemcdgayle
Butwait, there’s onemore thing...
READY? Follow up with your recruiter to schedule your next steps.
JOB POSTINGS: facebook.com/careers/teams/engineering
SLIDES? Gayle.com -> Events -> search “Facebook”
gayle in/gaylemcdgayleGayle Laakmann McDowell 81
Other Resources
Gayle.com
CareerCup.com
CrackingThe
CodingInterview.com
Or, follow me online
• facebook.com/gayle
• twitter.com/gayle
• gayle.com
• gayle@gayle.com
• quora.com

Más contenido relacionado

La actualidad más candente

Top 5 Mistakes When Writing Spark Applications by Mark Grover and Ted Malaska
Top 5 Mistakes When Writing Spark Applications by Mark Grover and Ted MalaskaTop 5 Mistakes When Writing Spark Applications by Mark Grover and Ted Malaska
Top 5 Mistakes When Writing Spark Applications by Mark Grover and Ted Malaska
Spark Summit
 

La actualidad más candente (20)

Top 5 Mistakes When Writing Spark Applications by Mark Grover and Ted Malaska
Top 5 Mistakes When Writing Spark Applications by Mark Grover and Ted MalaskaTop 5 Mistakes When Writing Spark Applications by Mark Grover and Ted Malaska
Top 5 Mistakes When Writing Spark Applications by Mark Grover and Ted Malaska
 
A really really fast introduction to PySpark - lightning fast cluster computi...
A really really fast introduction to PySpark - lightning fast cluster computi...A really really fast introduction to PySpark - lightning fast cluster computi...
A really really fast introduction to PySpark - lightning fast cluster computi...
 
Low Level CPU Performance Profiling Examples
Low Level CPU Performance Profiling ExamplesLow Level CPU Performance Profiling Examples
Low Level CPU Performance Profiling Examples
 
A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...
A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...
A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...
 
Apache Spark Core
Apache Spark CoreApache Spark Core
Apache Spark Core
 
Data Storage Tips for Optimal Spark Performance-(Vida Ha, Databricks)
Data Storage Tips for Optimal Spark Performance-(Vida Ha, Databricks)Data Storage Tips for Optimal Spark Performance-(Vida Ha, Databricks)
Data Storage Tips for Optimal Spark Performance-(Vida Ha, Databricks)
 
Demystifying MySQL Replication Crash Safety
Demystifying MySQL Replication Crash SafetyDemystifying MySQL Replication Crash Safety
Demystifying MySQL Replication Crash Safety
 
Top 5 Mistakes to Avoid When Writing Apache Spark Applications
Top 5 Mistakes to Avoid When Writing Apache Spark ApplicationsTop 5 Mistakes to Avoid When Writing Apache Spark Applications
Top 5 Mistakes to Avoid When Writing Apache Spark Applications
 
MySQL Parallel Replication by Booking.com
MySQL Parallel Replication by Booking.comMySQL Parallel Replication by Booking.com
MySQL Parallel Replication by Booking.com
 
Adaptive Query Execution: Speeding Up Spark SQL at Runtime
Adaptive Query Execution: Speeding Up Spark SQL at RuntimeAdaptive Query Execution: Speeding Up Spark SQL at Runtime
Adaptive Query Execution: Speeding Up Spark SQL at Runtime
 
Introduction to Spark
Introduction to SparkIntroduction to Spark
Introduction to Spark
 
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...
 
Spark SQL Join Improvement at Facebook
Spark SQL Join Improvement at FacebookSpark SQL Join Improvement at Facebook
Spark SQL Join Improvement at Facebook
 
SSD Deployment Strategies for MySQL
SSD Deployment Strategies for MySQLSSD Deployment Strategies for MySQL
SSD Deployment Strategies for MySQL
 
Ask the expert AEM Assets best practices 092016
Ask the expert  AEM Assets best practices 092016Ask the expert  AEM Assets best practices 092016
Ask the expert AEM Assets best practices 092016
 
Apache Spark in Depth: Core Concepts, Architecture & Internals
Apache Spark in Depth: Core Concepts, Architecture & InternalsApache Spark in Depth: Core Concepts, Architecture & Internals
Apache Spark in Depth: Core Concepts, Architecture & Internals
 
Beyond SQL: Speeding up Spark with DataFrames
Beyond SQL: Speeding up Spark with DataFramesBeyond SQL: Speeding up Spark with DataFrames
Beyond SQL: Speeding up Spark with DataFrames
 
MySQL 상태 메시지 분석 및 활용
MySQL 상태 메시지 분석 및 활용MySQL 상태 메시지 분석 및 활용
MySQL 상태 메시지 분석 및 활용
 
Load Data Fast!
Load Data Fast!Load Data Fast!
Load Data Fast!
 
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
 

Más de Gayle McDowell

Más de Gayle McDowell (13)

Cracking the PM Interview
Cracking the PM InterviewCracking the PM Interview
Cracking the PM Interview
 
Cracking the Coding interview (Abbreviated) - aug 2016
Cracking the Coding interview (Abbreviated) - aug 2016Cracking the Coding interview (Abbreviated) - aug 2016
Cracking the Coding interview (Abbreviated) - aug 2016
 
Cracking the PM Interview
Cracking the PM InterviewCracking the PM Interview
Cracking the PM Interview
 
Cracking the Product Manager Interview
Cracking the Product Manager InterviewCracking the Product Manager Interview
Cracking the Product Manager Interview
 
How to Hire Software Engineers: Best and Worst Practices
How to Hire Software Engineers: Best and Worst PracticesHow to Hire Software Engineers: Best and Worst Practices
How to Hire Software Engineers: Best and Worst Practices
 
Prepping Your Engineering Candidates to Reduce Your False Negatives
Prepping Your Engineering Candidates to Reduce Your False NegativesPrepping Your Engineering Candidates to Reduce Your False Negatives
Prepping Your Engineering Candidates to Reduce Your False Negatives
 
Creating the (Im)perfect Developer Interview
Creating the (Im)perfect Developer InterviewCreating the (Im)perfect Developer Interview
Creating the (Im)perfect Developer Interview
 
Hiring Great Product Managers
Hiring Great Product ManagersHiring Great Product Managers
Hiring Great Product Managers
 
Cracking the Product Manager Interview
Cracking the Product Manager InterviewCracking the Product Manager Interview
Cracking the Product Manager Interview
 
Reverse Engineering Engineering Interviewing: How to Be a Great Interviewer
Reverse Engineering Engineering Interviewing: How to Be a Great InterviewerReverse Engineering Engineering Interviewing: How to Be a Great Interviewer
Reverse Engineering Engineering Interviewing: How to Be a Great Interviewer
 
Transitioning from Engineering to Product Management
Transitioning from Engineering to Product ManagementTransitioning from Engineering to Product Management
Transitioning from Engineering to Product Management
 
Interviewing Great Developers: Reverse Engineering Interview Coaching to Crea...
Interviewing Great Developers: Reverse Engineering Interview Coaching to Crea...Interviewing Great Developers: Reverse Engineering Interview Coaching to Crea...
Interviewing Great Developers: Reverse Engineering Interview Coaching to Crea...
 
Cracking the Coding & PM Interview (Jan 2014)
Cracking the Coding & PM Interview (Jan 2014)Cracking the Coding & PM Interview (Jan 2014)
Cracking the Coding & PM Interview (Jan 2014)
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

Cracking the Facebook Coding Interview

  • 1. GayleL.McDowell | Founder/ CEO gayle in/gaylemcdgayle Cracking the Facebook Coding Interview I <3 Facebook! CareerCup
  • 2. Why am I here? 00
  • 3. gayle in/gaylemcdgayleGayle Laakmann McDowell 3 Why wouldFacebookprepyou?!? Be more comfortable Be more prepared Take out the mystery Avoid common mistakes
  • 4. gayle in/gaylemcdgayleGayle Laakmann McDowell 4 Hi! I’m Gayle LaakmannMcDowell Author Interview Coach Interview Consulting <dev> </dev> (CS) (MBA)
  • 5. Gayle Laakmann McDowell 5gayle in/gaylemcdgayle Yes! Slidesare online! Gayle.com  Click “Events”  Ctrl-F for “Facebook”
  • 7. gayle in/gaylemcdgayleGayle Laakmann McDowell 7 A Typical**Process(**notuniversal!Askyourrecruiter) Phone Onsite HiringCommittee & Decision ½ Behavioral ½ Algo / Coding Design Algo / Coding Algo / Coding Algo / Coding
  • 8. gayle in/gaylemcdgayle 8 z Gayle Laakmann McDowell Typical Coding Interview 5 Minutes Questions FORInterviewer 35 Minutes Question #1 Question#2 5 Minutes Prior Experience
  • 9. gayle in/gaylemcdgayle 9 z Gayle Laakmann McDowell Typical Design Interview 5 Minutes Questions FORInterviewer 35 Minutes Question#1 5 Minutes Prior Experience
  • 11. gayle in/gaylemcdgayleGayle Laakmann McDowell 11 The Pitch /Resume Walk-Through • Showsof success • Prompt the interviewer • Hobbies I’masoftwareengineerat... Mybackground’sinCS. IstudiedatUPennandthen… Atmycurrentcompany,I… OutsideofworkI…
  • 12. Gayle Laakmann McDowell 12gayle in/gaylemcdgayle Your Past Work 3+ Projects  Hard / cool  You werecentral  Technical depth All Past Work  TECHNICAL:Challenges, architecture, tradeoffs, successes, motivations  SOFT:Teamwork, leadership, conflicts, etc What did YOU do? What would you do differently?
  • 13. gayle in/gaylemcdgayle 13 z Gayle Laakmann McDowell What about YOU? Be PASSIONATE Be KNOWLEDGEABLE Be a GOOD TEAMMATE
  • 15. gayle in/gaylemcdgayle 15 z Gayle Laakmann McDowell How To Approach W W Y D A W hat ould ou o t ork
  • 16. gayle in/gaylemcdgayle 16 z Gayle Laakmann McDowell How To Approach S K I R cope eycomponents dentify issues epair
  • 17. gayle in/gaylemcdgayle 17 z Gayle Laakmann McDowell How To Approach ① Scope the Problem  Askquestions  Make appropriateassumptions ② Define Key Components  Can besomewhatnaïve ③ Identify Issues  Bottlenecks,tradeoffs ④ Repair & Redesign Breadth-first,notdepth-first
  • 18. Gayle Laakmann McDowell 18gayle in/gaylemcdgayle ExampleQuestion
  • 19. Gayle Laakmann McDowell 19gayle in/gaylemcdgayle Design sketch Frontend Backend Data store logger
  • 20. Gayle Laakmann McDowell 20gayle in/gaylemcdgayle Collaborativediscussionthat you’re driving! DRIVE  Leadtheprocess  Be openaboutissues TEAMWORK  Be opentofeedback  Tweak asnecessary Usethewhiteboard!
  • 21. gayle in/gaylemcdgayle 21 z Gayle Laakmann McDowell How To Prepare Read about design of major companies  THINK, don’t memorize! Know key concepts  Tasks, sharding, caches.  Web stack, REST, etc Practice back-of-the-envelope calculations
  • 23. Gayle Laakmann McDowell 23gayle in/gaylemcdgayle Why? Analytical skills How you think Make tradeoffs Pushthrough hard problems Communication Strong CS fundamentals
  • 24. gayle in/gaylemcdgayleGayle Laakmann McDowell 24 Essential Knowledge Data Structures Algorithms Concepts ArrayLists Merge Sort BigO Time Hash Tables QuickSort BigO Space Trees(+Tries) & Graphs Breadth-FirstSearch Recursion LinkedLists Depth-FirstSearch Memoization/ Dynamic Programming Stacks/ Queues BinarySearch Heaps
  • 25. gayle in/gaylemcdgayleGayle Laakmann McDowell 25 Preparation MASTER Big O ImplementDS/Algorithms Practicewith interview questions Code on paper/whiteboard Mock interviews PUSHYOURSELF!
  • 26. A Crash Course in Big O Just getting your feet wet
  • 27. gayle in/gaylemcdgayleGayle Laakmann McDowell 27 Basicfor loop Print0 throughN Runtime?  O(N)
  • 28. gayle in/gaylemcdgayleGayle Laakmann McDowell 28 Two loops Printevens, thenodds Runtime?O(N)
  • 29. gayle in/gaylemcdgayleGayle Laakmann McDowell 29 Basicfor loop Printpairs from two arrays Runtime?  O(A*B)
  • 30. gayle in/gaylemcdgayleGayle Laakmann McDowell 30 Basicfor loop Printordered pairs Runtime?  O(N2) j : 0  N i:0N x x x x x x x x x x x x x x x x x x x x x
  • 31. gayle in/gaylemcdgayleGayle Laakmann McDowell 31 Okay now thingsare getting tougher!
  • 32. gayle in/gaylemcdgayleGayle Laakmann McDowell 32 Okay now thingsare getting tougher! Step 1: O(P)  P = numberof people Step 2: O(P * Y)  Y = max life span Step 3: O(L)  L = last death year O(P + P * Y + L)  O(P * Y + L)
  • 33. gayle in/gaylemcdgayleGayle Laakmann McDowell 33 Validate Validate Runtime?  undefined
  • 34. gayle in/gaylemcdgayleGayle Laakmann McDowell 34 Fibonacci Runtime? Eeek. Recursion?
  • 35. gayle in/gaylemcdgayleGayle Laakmann McDowell 35 Fibonacci Eeek. Recursion? • Height of N • Each level doubles # nodes •  O(2N) time *** •  O(N) space Actuallyslightlylessforcomplexmathreasons.
  • 36. gayle in/gaylemcdgayleGayle Laakmann McDowell 36 Fibonacci, part 2 Runtime? Eeek. Recursion? • Height of N • Each level has <=2nodes •  O(N) time •  O(N) space
  • 37. gayle in/gaylemcdgayleGayle Laakmann McDowell 37 Reminders Drop constants Don’t drop non-constants Differentvariables Avoid ‘n’ Add vs. Multiply Recursion call tree
  • 38. Solving Algorithms How to… attempt to solve a hard problem
  • 39. gayle in/gaylemcdgayle 39 z Gayle Laakmann McDowell What is NOT expected To know the answers To solve immediately To code perfectly (It’snice.Itjustdoesn’t happen*.) *Okayfine.Ithappenedonce,in2000+hiringpackets.
  • 40. gayle in/gaylemcdgayle 40 z Gayle Laakmann McDowell What IS expected Be excitedabout hard problems Drive!  Keep trying when stuck  More than just “correct” Pay attention to me! Write real code Showmehowyouthink!
  • 41. gayle in/gaylemcdgayle 41 z Gayle Laakmann McDowell How To Approach CrackingTheCodingInterview.com“Resources”
  • 42. gayle in/gaylemcdgayle 42Gayle Laakmann McDowell step Listen (for clues)
  • 43. Gayle Laakmann McDowell 43gayle in/gaylemcdgayle What’s the clue? Anagram server  Ex: rates ->aster, stare, taser, tears Clue:why is it on a server? Key(sorted string) Value (list of words) aerst rates, aster, stare, taser, tears, dgo dog, god acll call … …
  • 44. gayle in/gaylemcdgayle 44Gayle Laakmann McDowell step Draw an Example INTERSECTION SIZE: Find # elementsin common between two sorted, distinct arrays:
  • 45. gayle in/gaylemcdgayleGayle Laakmann McDowell 45 Ex:Intersection ofTwo Sorted Arrays Most people draw somethinglike this: [1, 12, 15, 19] [2, 12, 13, 20]  Toosmall  Toospecial-case-y • same size, one commonelement, same index
  • 46. gayle in/gaylemcdgayleGayle Laakmann McDowell 46 Ex:Intersection ofTwo Sorted Arrays Better: [1, 12, 15, 19, 20, 21] [2, 15, 17, 19, 21, 25, 27]  Big  No specialcases
  • 47. gayle in/gaylemcdgayle 47Gayle Laakmann McDowell step Draw an Example Big Enough General Purpose +
  • 48. gayle in/gaylemcdgayle 48Gayle Laakmann McDowell step Brute Force / Naive Stupid&terribleisokay!
  • 49. gayle in/gaylemcdgayle 49Gayle Laakmann McDowell step Optimize Walk through brute force Look for optimizations
  • 50. Gayle Laakmann McDowell 50gayle in/gaylemcdgayle Techniquesto Develop Algorithms BUD Space and Time Do It Yourself Recursion
  • 51. Gayle Laakmann McDowell 51gayle in/gaylemcdgayle (A) Look for BUD Bottlenecks Unnecessary work Duplicated work
  • 52. Gayle Laakmann McDowell 52gayle in/gaylemcdgayle What’s the bottleneck?  Ex: countingthe intersection [1, 12, 15, 19, 20, 21] [2, 15, 17, 19, 21, 25, 27]  Bottleneck:searching B
  • 53. Gayle Laakmann McDowell 53gayle in/gaylemcdgayle What’s unnecessary?  Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000  Unnecessary: looking for d U
  • 54. Gayle Laakmann McDowell 54gayle in/gaylemcdgayle What’s unnecessary?  Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000  Unnecessary: looking for d U
  • 55. Gayle Laakmann McDowell 55gayle in/gaylemcdgayle What’s duplicated?  Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000  Duplicated: c, d pairs D
  • 56. Gayle Laakmann McDowell 56gayle in/gaylemcdgayle What’s duplicated?  Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000  Duplicated: c, d pairs D c d c3 + d3 … … … 4 31 29855 4 32 32832 4 33 36001 … … … 5 59 205504 5 60 216125 5 61 227106 … … …
  • 57. Gayle Laakmann McDowell 57gayle in/gaylemcdgayle What’s duplicated?  Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000  Duplicated: c, d pairs D c3 + d3 (c, d) … … 29855 (4, 31) 32832 (4, 32),(18, 30) 36001 (4, 33) … … 205504 (5, 59) 216125 (5, 60),(45, 50) 227106 (5, 61) … …
  • 58. Gayle Laakmann McDowell 58gayle in/gaylemcdgayle What’s duplicated?  Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000 D
  • 59. Gayle Laakmann McDowell 59gayle in/gaylemcdgayle What’s duplicated?  Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000 D
  • 60. Gayle Laakmann McDowell 60gayle in/gaylemcdgayle (B)Space/TimeTradeoffs Hashtables & other datastructures Precomputing
  • 61. Gayle Laakmann McDowell 61gayle in/gaylemcdgayle (C)Do it yourself Findpermutationsof swithinb
  • 62. gayle in/gaylemcdgayleGayle Laakmann McDowell 62 find abbcd in b a b c d b a e f d b b a c b d d f a e 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
  • 63. Gayle Laakmann McDowell 63gayle in/gaylemcdgayle (C)Do it yourself Findpermutationsof swithinb  s = abbcd  b = Findthem!  … now how didyou actuallydoit? b a b c d b a e f d b b a c b d d f a e
  • 64. Gayle Laakmann McDowell 64gayle in/gaylemcdgayle (D)Recursion  Use, but don’t cling to, recursion “instinct”  Trybottom-up  “Backtracking”  Draw call-tree  Derive runtime  Find repeated subproblems  Subsets of a set  {} {}  {a}{},{a}  {a,b} {},{a},{b},{a,b}  {a,b, c} …  Subsets of {S1…Sn-1} +Sn to each
  • 65. Gayle Laakmann McDowell 65gayle in/gaylemcdgayle Techniquesto Develop Algorithms BUD Space and Time Do It Yourself Recursion
  • 66. gayle in/gaylemcdgayle 66Gayle Laakmann McDowell step Walk Through Know the variables andwhen they change
  • 67. gayle in/gaylemcdgayle 67Gayle Laakmann McDowell step Write Beautiful Code
  • 68. Gayle Laakmann McDowell 68gayle in/gaylemcdgayle How toWrite WhiteboardCode Write straight Top-leftcorner Use arrows if needed Error cases Good style Modularize (upfront!) Languagechoiceisuptoyou!
  • 69. Gayle Laakmann McDowell 69gayle in/gaylemcdgayle Error Cases Good to check errors / boundaries! But consider the time…
  • 70. gayle in/gaylemcdgayleGayle Laakmann McDowell 70 Good Style Spacing, line breaks, variable names
  • 71. Gayle Laakmann McDowell 71gayle in/gaylemcdgayle Language Choice Java, Objective C, etc:Abbreviate Python, Ruby, JS,etc: Carefulwithbuilt-infunctions
  • 72. gayle in/gaylemcdgayleGayle Laakmann McDowell 72 Modularization
  • 73. Gayle Laakmann McDowell 73gayle in/gaylemcdgayle Modularize(Upfront!) I’ve learned nothing.
  • 74. gayle in/gaylemcdgayle 74Gayle Laakmann McDowell step Testing FIRST Analyze  What’s it doing? Why?  Anything that looks weird?  Errorhot spots THEN use test cases  Small test cases  Edge cases  Biggertest cases BUT…  Test code, notalgorithm  Think as you test  Think before you fix Find permutationsof s withinb: s = abbc b = babcabbacaabcbabcacbb for (i = 0; i < b.len – s.len; i++) { if (isPerm(s, b.subs(i, s.len)) … }
  • 75. gayle in/gaylemcdgayle 75 z Gayle Laakmann McDowell How To Approach CrackingTheCodingInterview.com“Resources”
  • 76. Questions for Your Interviewer What do you want to know? 05
  • 77. Gayle Laakmann McDowell 77gayle in/gaylemcdgayle Prepare some questions What’s made you happy / unhappy? What are your goals? Culture& work style Career paths Technology Interviewer’s experience
  • 79. gayle in/gaylemcdgayle 79 z Gayle Laakmann McDowell It’s done for a reason! Be agreat teammate. Be a great engineer.
  • 80. Gayle Laakmann McDowell 80gayle in/gaylemcdgayle Butwait, there’s onemore thing... READY? Follow up with your recruiter to schedule your next steps. JOB POSTINGS: facebook.com/careers/teams/engineering SLIDES? Gayle.com -> Events -> search “Facebook”
  • 81. gayle in/gaylemcdgayleGayle Laakmann McDowell 81 Other Resources Gayle.com CareerCup.com CrackingThe CodingInterview.com Or, follow me online • facebook.com/gayle • twitter.com/gayle • gayle.com • gayle@gayle.com • quora.com