SlideShare a Scribd company logo
1 of 53
GayleL.McDowell | Founder/ CEO
gayle in/gaylemcdgayle
Cracking the Algorithm &
Coding Interview
SVCC
SiliconValleyCodeCamp
gayle in/gaylemcdgayleGayle Laakmann McDowell 2
Hi! I’m Gayle LaakmannMcDowell
Author Interview Coach Interview Consulting
<dev> </dev>
(CS) (MBA)
Gayle Laakmann McDowell 3gayle in/gaylemcdgayle
Yes! Slidesare online!
Gayle.com
 Click“Events”
 Ctrl-F for “SiliconValley”
But why?
Why why why why why why meeeee
01
gayle in/gaylemcdgayle 5
z
Gayle Laakmann McDowell
What
Really
Happens
Gayle Laakmann McDowell 6gayle in/gaylemcdgayle
Why?
Strong CS
fundamentals
Analytical skills
Make tradeoffs
Push throughhard
problems
Communication
How you think
Preparation
Why why why why why why meeeee
02
gayle in/gaylemcdgayleGayle Laakmann McDowell 8
Essential Knowledge
Data Structures Algorithms Concepts
ArrayLists Merge Sort BigO Time
Hash Tables QuickSort BigO Space
Trees(+Tries) Breadth-FirstSearch Recursion
Graphs Depth-FirstSearch Memoization/ Dynamic
Programming
Stacks/ Queues BinarySearch
Heaps
gayle in/gaylemcdgayleGayle Laakmann McDowell 9
Preparation
ImplementDS/Algorithms
MASTER BigO
Practice with interviewquestions
Code on paper/whiteboard
Mock interviews
PUSHYOURSELF!
Expectations &
Evaluation
Why why why why why why meeeee
03
gayle in/gaylemcdgayle 11
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 12
z
Gayle Laakmann McDowell
What
IS
expected
Be excitedabout hard problems
More thanjust “correct”
Drive!
Keeptrying when stuck
Write real code
Showmehowyouthink!
gayle in/gaylemcdgayle 13
z
Gayle Laakmann McDowell
How
You’re
Evaluated
RELATIVE
Not a “metric” / timer
Nooneisperfect!
Solving
Why why why why why why meeeee
04
gayle in/gaylemcdgayle 15
z
Gayle Laakmann McDowell
How
To
Approach
CrackingTheCodingInterview.com“Resources”
gayle in/gaylemcdgayle 16Gayle Laakmann McDowell
step
Listen (for clues)
Gayle Laakmann McDowell 17gayle in/gaylemcdgayle
What’sthe clue?
Anagram server
 Ex: rates ->aster, stare, taser, tears
Clue:why is it ona server?
gayle in/gaylemcdgayle 18Gayle Laakmann McDowell
step
Draw an Example
Big Enough
General Purpose
+
gayle in/gaylemcdgayleGayle Laakmann McDowell 19
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 common element, sameindex
gayle in/gaylemcdgayleGayle Laakmann McDowell 20
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 21Gayle Laakmann McDowell
step
Brute Force / Naive
Stupid&terribleisokay!
gayle in/gaylemcdgayle 22Gayle Laakmann McDowell
step
Optimize
Walk through brute
force
Look for optimizations
Gayle Laakmann McDowell 23gayle in/gaylemcdgayle
Techniques to Develop Algorithms
Optimize
A. BUD
B. Space/time
C. Doityourself
Solve
D. Recursion
E. Solve “incorrectly”
F. Other data structures
Pushyourself!
Gayle Laakmann McDowell 24gayle in/gaylemcdgayle
(A) Look for BUD
Bottlenecks
Unnecessary work
Duplicated work
Gayle Laakmann McDowell 25gayle 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 26gayle in/gaylemcdgayle
What’s unnecessary?
 Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000
 Unnecessary: looking for d
U
Gayle Laakmann McDowell 27gayle in/gaylemcdgayle
What’s unnecessary?
 Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000
 Unnecessary: looking for d
U
Gayle Laakmann McDowell 28gayle in/gaylemcdgayle
What’s duplicated?
 Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000
 Duplicated: c, d pairs
D
Gayle Laakmann McDowell 29gayle in/gaylemcdgayle
What’s duplicated?
 Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000
 Duplicated: c, d pairs
D
Gayle Laakmann McDowell 30gayle in/gaylemcdgayle
What’s duplicated?
 Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000
D
Gayle Laakmann McDowell 31gayle in/gaylemcdgayle
What’s duplicated?
 Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000
D
Gayle Laakmann McDowell 32gayle in/gaylemcdgayle
(B)Space/TimeTradeoffs
Hashtables & other datastructures
Precomputing
Gayle Laakmann McDowell 33gayle in/gaylemcdgayle
Space/Time Tradeoffs Hashtables
 Find # pairs withsum
INPUT: array = [5, 15, 8, 9, 3, 2, -1, 4]
sum = 7
OUTPUT: 3
pairs = (5, 2), (8, -1), (3, 4)
 Putitemsinto hashtable
Gayle Laakmann McDowell 34gayle in/gaylemcdgayle
Space/Time Tradeoffs  Precomputing
 Find rectangle at origin w biggest sum
6 5 -9 2
-2 -5 -2 7
3 -2 10 13
-8 -3 1 -2
 Brute force: compute all rectanglesand sums
Gayle Laakmann McDowell 35gayle in/gaylemcdgayle
Space/Time Tradeoffs  Precomputing
 Find rectangle with biggest sum
6 5 -9 2
-2 -5 -2 7
3 -2 10 13
-8 -3 1 -2
-+ + 10=
Gayle Laakmann McDowell 36gayle in/gaylemcdgayle
Space/Time Tradeoffs  Precomputing
 Find rectangle with biggest sum
6 5 -9 2
-2 -5 -2 7
3 -2 10 13
-8 -3 1 -2
-+ + 13=
Gayle Laakmann McDowell 37gayle in/gaylemcdgayle
(C)Do it yourself
Findpermutationsof swithinb
 s = abbc
 b = babcabbacaabcbabcacbb
Findthem!
 … now how didyou actuallydoit?
Gayle Laakmann McDowell 38gayle in/gaylemcdgayle
Techniques to Develop Algorithms
Optimize
A. BUD
B. Space/time
C. Doityourself
Solve
D. Recursion
E. Solve “incorrectly”
F. Other data structures
Pushyourself!
Gayle Laakmann McDowell 39gayle in/gaylemcdgayle
(D) Recursion/ Base Case & Build
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 40gayle in/gaylemcdgayle
(E) Solve “incorrectly”
① Develop incorrectsolution
② Identifywhy preciselyit’s incorrect
③ Repair
④ (& Repeat)
Gayle Laakmann McDowell 41gayle in/gaylemcdgayle
(E)Solve “incorrectly”
Random node in BST
Try: flipcoin
Coin=Heads
 Branch Left
Coin=Tails
 Branch Right
Gayle Laakmann McDowell 42gayle in/gaylemcdgayle
(E)Solve “incorrectly”
Random node in BST
Try: random number in {0, 1, 2}
R=0
 Branch Left
R=2
 Branch Right
R=1
 Return root
Gayle Laakmann McDowell 43gayle in/gaylemcdgayle
(E)Solve “incorrectly”
Random node in BST
Try:
 Return rootwith1/n probability
 Then flipcoin(heads left,tails->right)
Gayle Laakmann McDowell 44gayle in/gaylemcdgayle
(E)Solve “incorrectly”
Random node in BST
Try: pick random # 0 throughn-1
R=0
 Return root
R>left.size
 Branch right
1<=R<=left.size
 Branch left
Gayle Laakmann McDowell 45gayle in/gaylemcdgayle
(F) Other Data Structures
Giving outphone numbers
 “I wantany availablenumber”
 “I wantthisnumber”
Try: sorted array?Sorted linkedlist?Hashtable?
BST?
gayle in/gaylemcdgayle 46Gayle Laakmann McDowell
step
Walk Through
Know the variables
andwhen they change
gayle in/gaylemcdgayle 47Gayle Laakmann McDowell
step
Write Beautiful Code
Gayle Laakmann McDowell 48gayle in/gaylemcdgayle
How to Write WhiteboardCode
Modularized
Error cases / TODOs
Good variables
Write straight
Top-leftcorner
Use arrows if needed
Languagechoiceisuptoyou!
gayle in/gaylemcdgayleGayle Laakmann McDowell 49
Modularization
gayle in/gaylemcdgayle 50Gayle Laakmann McDowell
step
Testing
FIRST Analyze
 What’sitdoing?Why?
 Anythingthatlooksweird?
 Errorhotspots
THEN use test cases
 Smalltestcases
 Edgecases
 Bigger testcases
Final Thoughts
And questions
05
gayle in/gaylemcdgayle 52
z
Gayle Laakmann McDowell
It’s done
for a
reason!
Be a great teammate.
Be a great engineer.
gayle in/gaylemcdgayleGayle Laakmann McDowell 53
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

More Related Content

What's hot

Introduction to Drools
Introduction to DroolsIntroduction to Drools
Introduction to Drools
giurca
 
Boost Performance With My S Q L 51 Partitions
Boost Performance With  My S Q L 51 PartitionsBoost Performance With  My S Q L 51 Partitions
Boost Performance With My S Q L 51 Partitions
PerconaPerformance
 
Oracle db performance tuning
Oracle db performance tuningOracle db performance tuning
Oracle db performance tuning
Simon Huang
 

What's hot (20)

Reading the .explain() Output
Reading the .explain() OutputReading the .explain() Output
Reading the .explain() Output
 
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
 
ZIO-Direct - Functional Scala 2022
ZIO-Direct - Functional Scala 2022ZIO-Direct - Functional Scala 2022
ZIO-Direct - Functional Scala 2022
 
Capabilities for Resources and Effects
Capabilities for Resources and EffectsCapabilities for Resources and Effects
Capabilities for Resources and Effects
 
MySQL Database Architectures - 2020-10
MySQL Database Architectures -  2020-10MySQL Database Architectures -  2020-10
MySQL Database Architectures - 2020-10
 
Clean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a MonolithClean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a Monolith
 
Top NoSQL Data Modeling Mistakes
Top NoSQL Data Modeling MistakesTop NoSQL Data Modeling Mistakes
Top NoSQL Data Modeling Mistakes
 
PgTAP Best Practices
PgTAP Best PracticesPgTAP Best Practices
PgTAP Best Practices
 
Running GA4 without gtag.js using ssGTM and elbwalker
Running GA4 without gtag.js using ssGTM and elbwalkerRunning GA4 without gtag.js using ssGTM and elbwalker
Running GA4 without gtag.js using ssGTM and elbwalker
 
Solving PostgreSQL wicked problems
Solving PostgreSQL wicked problemsSolving PostgreSQL wicked problems
Solving PostgreSQL wicked problems
 
Introduction to web programming with JavaScript
Introduction to web programming with JavaScriptIntroduction to web programming with JavaScript
Introduction to web programming with JavaScript
 
Introduction to Drools
Introduction to DroolsIntroduction to Drools
Introduction to Drools
 
Boost Performance With My S Q L 51 Partitions
Boost Performance With  My S Q L 51 PartitionsBoost Performance With  My S Q L 51 Partitions
Boost Performance With My S Q L 51 Partitions
 
Oracle db performance tuning
Oracle db performance tuningOracle db performance tuning
Oracle db performance tuning
 
Tanel Poder Oracle Scripts and Tools (2010)
Tanel Poder Oracle Scripts and Tools (2010)Tanel Poder Oracle Scripts and Tools (2010)
Tanel Poder Oracle Scripts and Tools (2010)
 
Sql query patterns, optimized
Sql query patterns, optimizedSql query patterns, optimized
Sql query patterns, optimized
 
Functional Domain Modeling - The ZIO 2 Way
Functional Domain Modeling - The ZIO 2 WayFunctional Domain Modeling - The ZIO 2 Way
Functional Domain Modeling - The ZIO 2 Way
 
Introduction to Cassandra Basics
Introduction to Cassandra BasicsIntroduction to Cassandra Basics
Introduction to Cassandra Basics
 
A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVM
 
MongoDB at Baidu
MongoDB at BaiduMongoDB at Baidu
MongoDB at Baidu
 

More from Gayle McDowell

More from Gayle McDowell (15)

Cracking the Coding Interview - 7 steps - Udacity
Cracking the Coding Interview - 7 steps - UdacityCracking the Coding Interview - 7 steps - Udacity
Cracking the Coding Interview - 7 steps - Udacity
 
Cracking the PM Interview
Cracking the PM InterviewCracking the PM Interview
Cracking the PM Interview
 
How to Interview Like Google (But Better) - SVCC
How to Interview Like Google (But Better) - SVCCHow to Interview Like Google (But Better) - SVCC
How to Interview Like Google (But Better) - SVCC
 
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
 
Cracking the Coding Interview
Cracking the Coding InterviewCracking the Coding Interview
Cracking the Coding 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...
 

Recently uploaded

Zeeman Effect normal and Anomalous zeeman effect
Zeeman Effect normal and Anomalous zeeman effectZeeman Effect normal and Anomalous zeeman effect
Zeeman Effect normal and Anomalous zeeman effect
PriyanshuRawat56
 
0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf
0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf
0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf
ssuserded2d4
 
OSU毕业证留学文凭,制做办理
OSU毕业证留学文凭,制做办理OSU毕业证留学文凭,制做办理
OSU毕业证留学文凭,制做办理
cowagem
 
Virgin Call Girls Delhi Service-oriented sexy call girls ☞ 9899900591 ☜ Rita ...
Virgin Call Girls Delhi Service-oriented sexy call girls ☞ 9899900591 ☜ Rita ...Virgin Call Girls Delhi Service-oriented sexy call girls ☞ 9899900591 ☜ Rita ...
Virgin Call Girls Delhi Service-oriented sexy call girls ☞ 9899900591 ☜ Rita ...
poojakaurpk09
 
Call Girls Btm Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Btm Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Btm Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Btm Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
amitlee9823
 
Call Girls Bidadi ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Call Girls Bidadi ☎ 7737669865☎ Book Your One night Stand (Bangalore)Call Girls Bidadi ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Call Girls Bidadi ☎ 7737669865☎ Book Your One night Stand (Bangalore)
amitlee9823
 
Vip Modals Call Girls (Delhi) Rohini 9711199171✔️ Full night Service for one...
Vip  Modals Call Girls (Delhi) Rohini 9711199171✔️ Full night Service for one...Vip  Modals Call Girls (Delhi) Rohini 9711199171✔️ Full night Service for one...
Vip Modals Call Girls (Delhi) Rohini 9711199171✔️ Full night Service for one...
shivangimorya083
 
CALL ON ➥8923113531 🔝Call Girls Gosainganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Gosainganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Gosainganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Gosainganj Lucknow best sexual service
anilsa9823
 
Internship Report].pdf iiwmoosmsosmshkssmk
Internship Report].pdf iiwmoosmsosmshkssmkInternship Report].pdf iiwmoosmsosmshkssmk
Internship Report].pdf iiwmoosmsosmshkssmk
SujalTamhane
 
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdfreStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
Ken Fuller
 
Presentation on Workplace Politics.ppt..
Presentation on Workplace Politics.ppt..Presentation on Workplace Politics.ppt..
Presentation on Workplace Politics.ppt..
Masuk Ahmed
 

Recently uploaded (20)

VVVIP Call Girls In East Of Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In East Of Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...VVVIP Call Girls In East Of Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In East Of Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
 
Hot Call Girls |Delhi |Janakpuri ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Janakpuri ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Janakpuri ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Janakpuri ☎ 9711199171 Book Your One night Stand
 
Zeeman Effect normal and Anomalous zeeman effect
Zeeman Effect normal and Anomalous zeeman effectZeeman Effect normal and Anomalous zeeman effect
Zeeman Effect normal and Anomalous zeeman effect
 
CFO_SB_Career History_Multi Sector Experience
CFO_SB_Career History_Multi Sector ExperienceCFO_SB_Career History_Multi Sector Experience
CFO_SB_Career History_Multi Sector Experience
 
0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf
0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf
0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf
 
OSU毕业证留学文凭,制做办理
OSU毕业证留学文凭,制做办理OSU毕业证留学文凭,制做办理
OSU毕业证留学文凭,制做办理
 
Virgin Call Girls Delhi Service-oriented sexy call girls ☞ 9899900591 ☜ Rita ...
Virgin Call Girls Delhi Service-oriented sexy call girls ☞ 9899900591 ☜ Rita ...Virgin Call Girls Delhi Service-oriented sexy call girls ☞ 9899900591 ☜ Rita ...
Virgin Call Girls Delhi Service-oriented sexy call girls ☞ 9899900591 ☜ Rita ...
 
Call Girls Btm Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Btm Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Btm Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Btm Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
 
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Sa...
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Sa...Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Sa...
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Sa...
 
Call Girls Bidadi ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Call Girls Bidadi ☎ 7737669865☎ Book Your One night Stand (Bangalore)Call Girls Bidadi ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Call Girls Bidadi ☎ 7737669865☎ Book Your One night Stand (Bangalore)
 
Dark Dubai Call Girls O525547819 Skin Call Girls Dubai
Dark Dubai Call Girls O525547819 Skin Call Girls DubaiDark Dubai Call Girls O525547819 Skin Call Girls Dubai
Dark Dubai Call Girls O525547819 Skin Call Girls Dubai
 
Booking open Available Pune Call Girls Ambegaon Khurd 6297143586 Call Hot In...
Booking open Available Pune Call Girls Ambegaon Khurd  6297143586 Call Hot In...Booking open Available Pune Call Girls Ambegaon Khurd  6297143586 Call Hot In...
Booking open Available Pune Call Girls Ambegaon Khurd 6297143586 Call Hot In...
 
Vip Modals Call Girls (Delhi) Rohini 9711199171✔️ Full night Service for one...
Vip  Modals Call Girls (Delhi) Rohini 9711199171✔️ Full night Service for one...Vip  Modals Call Girls (Delhi) Rohini 9711199171✔️ Full night Service for one...
Vip Modals Call Girls (Delhi) Rohini 9711199171✔️ Full night Service for one...
 
CALL ON ➥8923113531 🔝Call Girls Gosainganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Gosainganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Gosainganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Gosainganj Lucknow best sexual service
 
Joshua Minker Brand Exploration Sports Broadcaster .pptx
Joshua Minker Brand Exploration Sports Broadcaster .pptxJoshua Minker Brand Exploration Sports Broadcaster .pptx
Joshua Minker Brand Exploration Sports Broadcaster .pptx
 
Internship Report].pdf iiwmoosmsosmshkssmk
Internship Report].pdf iiwmoosmsosmshkssmkInternship Report].pdf iiwmoosmsosmshkssmk
Internship Report].pdf iiwmoosmsosmshkssmk
 
Toxicokinetics studies.. (toxicokinetics evaluation in preclinical studies)
Toxicokinetics studies.. (toxicokinetics evaluation in preclinical studies)Toxicokinetics studies.. (toxicokinetics evaluation in preclinical studies)
Toxicokinetics studies.. (toxicokinetics evaluation in preclinical studies)
 
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdfreStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
 
Presentation on Workplace Politics.ppt..
Presentation on Workplace Politics.ppt..Presentation on Workplace Politics.ppt..
Presentation on Workplace Politics.ppt..
 
Brand Analysis for reggaeton artist Jahzel.
Brand Analysis for reggaeton artist Jahzel.Brand Analysis for reggaeton artist Jahzel.
Brand Analysis for reggaeton artist Jahzel.
 

Cracking the Algorithm & Coding Interview

  • 1. GayleL.McDowell | Founder/ CEO gayle in/gaylemcdgayle Cracking the Algorithm & Coding Interview SVCC SiliconValleyCodeCamp
  • 2. gayle in/gaylemcdgayleGayle Laakmann McDowell 2 Hi! I’m Gayle LaakmannMcDowell Author Interview Coach Interview Consulting <dev> </dev> (CS) (MBA)
  • 3. Gayle Laakmann McDowell 3gayle in/gaylemcdgayle Yes! Slidesare online! Gayle.com  Click“Events”  Ctrl-F for “SiliconValley”
  • 4. But why? Why why why why why why meeeee 01
  • 5. gayle in/gaylemcdgayle 5 z Gayle Laakmann McDowell What Really Happens
  • 6. Gayle Laakmann McDowell 6gayle in/gaylemcdgayle Why? Strong CS fundamentals Analytical skills Make tradeoffs Push throughhard problems Communication How you think
  • 7. Preparation Why why why why why why meeeee 02
  • 8. gayle in/gaylemcdgayleGayle Laakmann McDowell 8 Essential Knowledge Data Structures Algorithms Concepts ArrayLists Merge Sort BigO Time Hash Tables QuickSort BigO Space Trees(+Tries) Breadth-FirstSearch Recursion Graphs Depth-FirstSearch Memoization/ Dynamic Programming Stacks/ Queues BinarySearch Heaps
  • 9. gayle in/gaylemcdgayleGayle Laakmann McDowell 9 Preparation ImplementDS/Algorithms MASTER BigO Practice with interviewquestions Code on paper/whiteboard Mock interviews PUSHYOURSELF!
  • 10. Expectations & Evaluation Why why why why why why meeeee 03
  • 11. gayle in/gaylemcdgayle 11 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.
  • 12. gayle in/gaylemcdgayle 12 z Gayle Laakmann McDowell What IS expected Be excitedabout hard problems More thanjust “correct” Drive! Keeptrying when stuck Write real code Showmehowyouthink!
  • 13. gayle in/gaylemcdgayle 13 z Gayle Laakmann McDowell How You’re Evaluated RELATIVE Not a “metric” / timer Nooneisperfect!
  • 14. Solving Why why why why why why meeeee 04
  • 15. gayle in/gaylemcdgayle 15 z Gayle Laakmann McDowell How To Approach CrackingTheCodingInterview.com“Resources”
  • 16. gayle in/gaylemcdgayle 16Gayle Laakmann McDowell step Listen (for clues)
  • 17. Gayle Laakmann McDowell 17gayle in/gaylemcdgayle What’sthe clue? Anagram server  Ex: rates ->aster, stare, taser, tears Clue:why is it ona server?
  • 18. gayle in/gaylemcdgayle 18Gayle Laakmann McDowell step Draw an Example Big Enough General Purpose +
  • 19. gayle in/gaylemcdgayleGayle Laakmann McDowell 19 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 common element, sameindex
  • 20. gayle in/gaylemcdgayleGayle Laakmann McDowell 20 Ex:Intersection ofTwo Sorted Arrays Better: [1, 12, 15, 19, 20, 21] [2, 15, 17, 19, 21, 25, 27]  Big  No specialcases
  • 21. gayle in/gaylemcdgayle 21Gayle Laakmann McDowell step Brute Force / Naive Stupid&terribleisokay!
  • 22. gayle in/gaylemcdgayle 22Gayle Laakmann McDowell step Optimize Walk through brute force Look for optimizations
  • 23. Gayle Laakmann McDowell 23gayle in/gaylemcdgayle Techniques to Develop Algorithms Optimize A. BUD B. Space/time C. Doityourself Solve D. Recursion E. Solve “incorrectly” F. Other data structures Pushyourself!
  • 24. Gayle Laakmann McDowell 24gayle in/gaylemcdgayle (A) Look for BUD Bottlenecks Unnecessary work Duplicated work
  • 25. Gayle Laakmann McDowell 25gayle 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
  • 26. Gayle Laakmann McDowell 26gayle in/gaylemcdgayle What’s unnecessary?  Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000  Unnecessary: looking for d U
  • 27. Gayle Laakmann McDowell 27gayle in/gaylemcdgayle What’s unnecessary?  Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000  Unnecessary: looking for d U
  • 28. Gayle Laakmann McDowell 28gayle in/gaylemcdgayle What’s duplicated?  Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000  Duplicated: c, d pairs D
  • 29. Gayle Laakmann McDowell 29gayle in/gaylemcdgayle What’s duplicated?  Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000  Duplicated: c, d pairs D
  • 30. Gayle Laakmann McDowell 30gayle in/gaylemcdgayle What’s duplicated?  Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000 D
  • 31. Gayle Laakmann McDowell 31gayle in/gaylemcdgayle What’s duplicated?  Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000 D
  • 32. Gayle Laakmann McDowell 32gayle in/gaylemcdgayle (B)Space/TimeTradeoffs Hashtables & other datastructures Precomputing
  • 33. Gayle Laakmann McDowell 33gayle in/gaylemcdgayle Space/Time Tradeoffs Hashtables  Find # pairs withsum INPUT: array = [5, 15, 8, 9, 3, 2, -1, 4] sum = 7 OUTPUT: 3 pairs = (5, 2), (8, -1), (3, 4)  Putitemsinto hashtable
  • 34. Gayle Laakmann McDowell 34gayle in/gaylemcdgayle Space/Time Tradeoffs  Precomputing  Find rectangle at origin w biggest sum 6 5 -9 2 -2 -5 -2 7 3 -2 10 13 -8 -3 1 -2  Brute force: compute all rectanglesand sums
  • 35. Gayle Laakmann McDowell 35gayle in/gaylemcdgayle Space/Time Tradeoffs  Precomputing  Find rectangle with biggest sum 6 5 -9 2 -2 -5 -2 7 3 -2 10 13 -8 -3 1 -2 -+ + 10=
  • 36. Gayle Laakmann McDowell 36gayle in/gaylemcdgayle Space/Time Tradeoffs  Precomputing  Find rectangle with biggest sum 6 5 -9 2 -2 -5 -2 7 3 -2 10 13 -8 -3 1 -2 -+ + 13=
  • 37. Gayle Laakmann McDowell 37gayle in/gaylemcdgayle (C)Do it yourself Findpermutationsof swithinb  s = abbc  b = babcabbacaabcbabcacbb Findthem!  … now how didyou actuallydoit?
  • 38. Gayle Laakmann McDowell 38gayle in/gaylemcdgayle Techniques to Develop Algorithms Optimize A. BUD B. Space/time C. Doityourself Solve D. Recursion E. Solve “incorrectly” F. Other data structures Pushyourself!
  • 39. Gayle Laakmann McDowell 39gayle in/gaylemcdgayle (D) Recursion/ Base Case & Build Subsets of a set  {}  {}  {a}  {}, {a}  {a, b}  {}, {a}, {b}, {a, b}  {a, b, c}  … Subsets of {S1…Sn-1} + Sn to each
  • 40. Gayle Laakmann McDowell 40gayle in/gaylemcdgayle (E) Solve “incorrectly” ① Develop incorrectsolution ② Identifywhy preciselyit’s incorrect ③ Repair ④ (& Repeat)
  • 41. Gayle Laakmann McDowell 41gayle in/gaylemcdgayle (E)Solve “incorrectly” Random node in BST Try: flipcoin Coin=Heads  Branch Left Coin=Tails  Branch Right
  • 42. Gayle Laakmann McDowell 42gayle in/gaylemcdgayle (E)Solve “incorrectly” Random node in BST Try: random number in {0, 1, 2} R=0  Branch Left R=2  Branch Right R=1  Return root
  • 43. Gayle Laakmann McDowell 43gayle in/gaylemcdgayle (E)Solve “incorrectly” Random node in BST Try:  Return rootwith1/n probability  Then flipcoin(heads left,tails->right)
  • 44. Gayle Laakmann McDowell 44gayle in/gaylemcdgayle (E)Solve “incorrectly” Random node in BST Try: pick random # 0 throughn-1 R=0  Return root R>left.size  Branch right 1<=R<=left.size  Branch left
  • 45. Gayle Laakmann McDowell 45gayle in/gaylemcdgayle (F) Other Data Structures Giving outphone numbers  “I wantany availablenumber”  “I wantthisnumber” Try: sorted array?Sorted linkedlist?Hashtable? BST?
  • 46. gayle in/gaylemcdgayle 46Gayle Laakmann McDowell step Walk Through Know the variables andwhen they change
  • 47. gayle in/gaylemcdgayle 47Gayle Laakmann McDowell step Write Beautiful Code
  • 48. Gayle Laakmann McDowell 48gayle in/gaylemcdgayle How to Write WhiteboardCode Modularized Error cases / TODOs Good variables Write straight Top-leftcorner Use arrows if needed Languagechoiceisuptoyou!
  • 49. gayle in/gaylemcdgayleGayle Laakmann McDowell 49 Modularization
  • 50. gayle in/gaylemcdgayle 50Gayle Laakmann McDowell step Testing FIRST Analyze  What’sitdoing?Why?  Anythingthatlooksweird?  Errorhotspots THEN use test cases  Smalltestcases  Edgecases  Bigger testcases
  • 52. gayle in/gaylemcdgayle 52 z Gayle Laakmann McDowell It’s done for a reason! Be a great teammate. Be a great engineer.
  • 53. gayle in/gaylemcdgayleGayle Laakmann McDowell 53 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