SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

Testing Business Ideas by David Bland & Alex Osterwalder
Testing Business Ideas by David Bland & Alex Osterwalder Testing Business Ideas by David Bland & Alex Osterwalder
Testing Business Ideas by David Bland & Alex Osterwalder Peerasak C.
 
Framework for Running Minimum Viable Tests (MVT)
Framework for Running Minimum Viable Tests (MVT)Framework for Running Minimum Viable Tests (MVT)
Framework for Running Minimum Viable Tests (MVT)Conrad Wadowski
 
MongoDB World 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB World 2019: Tips and Tricks++ for Querying and Indexing MongoDBMongoDB World 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB World 2019: Tips and Tricks++ for Querying and Indexing MongoDBMongoDB
 
(Very) Recent AI advances for Chemical Engineering research and education
(Very) Recent AI advances for Chemical Engineering research and education(Very) Recent AI advances for Chemical Engineering research and education
(Very) Recent AI advances for Chemical Engineering research and educationRichard West
 
Startup Secrets: Wrap Up & Geoffrey Moore - An Insider’s Guide
Startup Secrets: Wrap Up & Geoffrey Moore - An Insider’s GuideStartup Secrets: Wrap Up & Geoffrey Moore - An Insider’s Guide
Startup Secrets: Wrap Up & Geoffrey Moore - An Insider’s GuideMichael Skok
 
JSON array indexes in MySQL
JSON array indexes in MySQLJSON array indexes in MySQL
JSON array indexes in MySQLDag H. Wanvik
 
Turning Products into Companies
Turning Products into CompaniesTurning Products into Companies
Turning Products into CompaniesMichael Skok
 
4 Strategies to Renew Your Career Passion
4 Strategies to Renew Your Career Passion4 Strategies to Renew Your Career Passion
4 Strategies to Renew Your Career PassionDaniel Goleman
 
Troubleshooting Deep Neural Networks - Full Stack Deep Learning
Troubleshooting Deep Neural Networks - Full Stack Deep LearningTroubleshooting Deep Neural Networks - Full Stack Deep Learning
Troubleshooting Deep Neural Networks - Full Stack Deep LearningSergey Karayev
 
Going to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific LanguagesGoing to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific LanguagesGuillaume Laforge
 
MongoDB World 2019: The Sights (and Smells) of a Bad Query
MongoDB World 2019: The Sights (and Smells) of a Bad QueryMongoDB World 2019: The Sights (and Smells) of a Bad Query
MongoDB World 2019: The Sights (and Smells) of a Bad QueryMongoDB
 
Turning Products Into Companies
Turning Products Into CompaniesTurning Products Into Companies
Turning Products Into CompaniesMichael Skok
 
Business DNA Model, Balanced Scorecard, and Strategy Map: A Visual Mathematic...
Business DNA Model, Balanced Scorecard, and Strategy Map: A Visual Mathematic...Business DNA Model, Balanced Scorecard, and Strategy Map: A Visual Mathematic...
Business DNA Model, Balanced Scorecard, and Strategy Map: A Visual Mathematic...Rod King, Ph.D.
 
Cracking the PM Interview
Cracking the PM InterviewCracking the PM Interview
Cracking the PM InterviewGayle McDowell
 
24 Ways to Outgrow and Outlearn Everyone (Including the Competition)
24 Ways to Outgrow and Outlearn Everyone (Including the Competition)24 Ways to Outgrow and Outlearn Everyone (Including the Competition)
24 Ways to Outgrow and Outlearn Everyone (Including the Competition)Étienne Garbugli
 

Tendances (20)

Testing Business Ideas by David Bland & Alex Osterwalder
Testing Business Ideas by David Bland & Alex Osterwalder Testing Business Ideas by David Bland & Alex Osterwalder
Testing Business Ideas by David Bland & Alex Osterwalder
 
Trees and Hierarchies in SQL
Trees and Hierarchies in SQLTrees and Hierarchies in SQL
Trees and Hierarchies in SQL
 
Models for hierarchical data
Models for hierarchical dataModels for hierarchical data
Models for hierarchical data
 
The YAGNI Principle
The YAGNI PrincipleThe YAGNI Principle
The YAGNI Principle
 
Depth of a Kanban Implementation
Depth of a Kanban ImplementationDepth of a Kanban Implementation
Depth of a Kanban Implementation
 
Framework for Running Minimum Viable Tests (MVT)
Framework for Running Minimum Viable Tests (MVT)Framework for Running Minimum Viable Tests (MVT)
Framework for Running Minimum Viable Tests (MVT)
 
Recursive Query Throwdown
Recursive Query ThrowdownRecursive Query Throwdown
Recursive Query Throwdown
 
MongoDB World 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB World 2019: Tips and Tricks++ for Querying and Indexing MongoDBMongoDB World 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB World 2019: Tips and Tricks++ for Querying and Indexing MongoDB
 
(Very) Recent AI advances for Chemical Engineering research and education
(Very) Recent AI advances for Chemical Engineering research and education(Very) Recent AI advances for Chemical Engineering research and education
(Very) Recent AI advances for Chemical Engineering research and education
 
Startup Secrets: Wrap Up & Geoffrey Moore - An Insider’s Guide
Startup Secrets: Wrap Up & Geoffrey Moore - An Insider’s GuideStartup Secrets: Wrap Up & Geoffrey Moore - An Insider’s Guide
Startup Secrets: Wrap Up & Geoffrey Moore - An Insider’s Guide
 
JSON array indexes in MySQL
JSON array indexes in MySQLJSON array indexes in MySQL
JSON array indexes in MySQL
 
Turning Products into Companies
Turning Products into CompaniesTurning Products into Companies
Turning Products into Companies
 
4 Strategies to Renew Your Career Passion
4 Strategies to Renew Your Career Passion4 Strategies to Renew Your Career Passion
4 Strategies to Renew Your Career Passion
 
Troubleshooting Deep Neural Networks - Full Stack Deep Learning
Troubleshooting Deep Neural Networks - Full Stack Deep LearningTroubleshooting Deep Neural Networks - Full Stack Deep Learning
Troubleshooting Deep Neural Networks - Full Stack Deep Learning
 
Going to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific LanguagesGoing to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific Languages
 
MongoDB World 2019: The Sights (and Smells) of a Bad Query
MongoDB World 2019: The Sights (and Smells) of a Bad QueryMongoDB World 2019: The Sights (and Smells) of a Bad Query
MongoDB World 2019: The Sights (and Smells) of a Bad Query
 
Turning Products Into Companies
Turning Products Into CompaniesTurning Products Into Companies
Turning Products Into Companies
 
Business DNA Model, Balanced Scorecard, and Strategy Map: A Visual Mathematic...
Business DNA Model, Balanced Scorecard, and Strategy Map: A Visual Mathematic...Business DNA Model, Balanced Scorecard, and Strategy Map: A Visual Mathematic...
Business DNA Model, Balanced Scorecard, and Strategy Map: A Visual Mathematic...
 
Cracking the PM Interview
Cracking the PM InterviewCracking the PM Interview
Cracking the PM Interview
 
24 Ways to Outgrow and Outlearn Everyone (Including the Competition)
24 Ways to Outgrow and Outlearn Everyone (Including the Competition)24 Ways to Outgrow and Outlearn Everyone (Including the Competition)
24 Ways to Outgrow and Outlearn Everyone (Including the Competition)
 

Plus de Gayle McDowell

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 2016Gayle McDowell
 
Cracking the PM Interview
Cracking the PM InterviewCracking the PM Interview
Cracking the PM InterviewGayle McDowell
 
Cracking the Product Manager Interview
Cracking the Product Manager InterviewCracking the Product Manager Interview
Cracking the Product Manager InterviewGayle McDowell
 
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 PracticesGayle McDowell
 
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 NegativesGayle McDowell
 
Creating the (Im)perfect Developer Interview
Creating the (Im)perfect Developer InterviewCreating the (Im)perfect Developer Interview
Creating the (Im)perfect Developer InterviewGayle McDowell
 
Hiring Great Product Managers
Hiring Great Product ManagersHiring Great Product Managers
Hiring Great Product ManagersGayle McDowell
 
Cracking the Coding Interview
Cracking the Coding InterviewCracking the Coding Interview
Cracking the Coding InterviewGayle McDowell
 
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 InterviewerGayle McDowell
 
Transitioning from Engineering to Product Management
Transitioning from Engineering to Product ManagementTransitioning from Engineering to Product Management
Transitioning from Engineering to Product ManagementGayle McDowell
 
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...Gayle McDowell
 
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)Gayle McDowell
 

Plus de Gayle McDowell (12)

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 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...
 
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)
 

Dernier

Miletti Gabriela_Vision Plan for artist Jahzel.pdf
Miletti Gabriela_Vision Plan for artist Jahzel.pdfMiletti Gabriela_Vision Plan for artist Jahzel.pdf
Miletti Gabriela_Vision Plan for artist Jahzel.pdfGabrielaMiletti
 
drug book file on obs. and gynae clinical pstings
drug book file on obs. and gynae clinical pstingsdrug book file on obs. and gynae clinical pstings
drug book file on obs. and gynae clinical pstingsKarishma7720
 
Top profile Call Girls In Shivamogga [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Shivamogga [ 7014168258 ] Call Me For Genuine Model...Top profile Call Girls In Shivamogga [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Shivamogga [ 7014168258 ] Call Me For Genuine Model...nirzagarg
 
Top profile Call Girls In Jabalpur [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Jabalpur [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Jabalpur [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Jabalpur [ 7014168258 ] Call Me For Genuine Models ...gajnagarg
 
Top profile Call Girls In Shillong [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Shillong [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Shillong [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Shillong [ 7014168258 ] Call Me For Genuine Models ...gajnagarg
 
怎样办理哥伦比亚大学毕业证(Columbia毕业证书)成绩单学校原版复制
怎样办理哥伦比亚大学毕业证(Columbia毕业证书)成绩单学校原版复制怎样办理哥伦比亚大学毕业证(Columbia毕业证书)成绩单学校原版复制
怎样办理哥伦比亚大学毕业证(Columbia毕业证书)成绩单学校原版复制yynod
 
Personal Brand Exploration ppt.- Ronnie Jones
Personal Brand  Exploration ppt.- Ronnie JonesPersonal Brand  Exploration ppt.- Ronnie Jones
Personal Brand Exploration ppt.- Ronnie Jonesjonesyde302
 
<DUBAI>Abortion pills IN UAE {{+971561686603*^Mifepristone & Misoprostol in D...
<DUBAI>Abortion pills IN UAE {{+971561686603*^Mifepristone & Misoprostol in D...<DUBAI>Abortion pills IN UAE {{+971561686603*^Mifepristone & Misoprostol in D...
<DUBAI>Abortion pills IN UAE {{+971561686603*^Mifepristone & Misoprostol in D...gynedubai
 
Top profile Call Girls In Ratnagiri [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Ratnagiri [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Ratnagiri [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Ratnagiri [ 7014168258 ] Call Me For Genuine Models...gajnagarg
 
B.tech Civil Engineering Major Project by Deepak Kumar ppt.pdf
B.tech Civil Engineering Major Project by Deepak Kumar ppt.pdfB.tech Civil Engineering Major Project by Deepak Kumar ppt.pdf
B.tech Civil Engineering Major Project by Deepak Kumar ppt.pdfDeepak15CivilEngg
 
Top profile Call Girls In bhubaneswar [ 7014168258 ] Call Me For Genuine Mode...
Top profile Call Girls In bhubaneswar [ 7014168258 ] Call Me For Genuine Mode...Top profile Call Girls In bhubaneswar [ 7014168258 ] Call Me For Genuine Mode...
Top profile Call Girls In bhubaneswar [ 7014168258 ] Call Me For Genuine Mode...gajnagarg
 
Howrah [ Call Girls Kolkata ₹7.5k Pick Up & Drop With Cash Payment 8005736733...
Howrah [ Call Girls Kolkata ₹7.5k Pick Up & Drop With Cash Payment 8005736733...Howrah [ Call Girls Kolkata ₹7.5k Pick Up & Drop With Cash Payment 8005736733...
Howrah [ Call Girls Kolkata ₹7.5k Pick Up & Drop With Cash Payment 8005736733...HyderabadDolls
 
B.tech civil major project by Deepak Kumar
B.tech civil major project by Deepak KumarB.tech civil major project by Deepak Kumar
B.tech civil major project by Deepak KumarDeepak15CivilEngg
 
Top profile Call Girls In Sagar [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Sagar [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Sagar [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Sagar [ 7014168258 ] Call Me For Genuine Models We ...nirzagarg
 
一比一定(购)中央昆士兰大学毕业证(CQU毕业证)成绩单学位证
一比一定(购)中央昆士兰大学毕业证(CQU毕业证)成绩单学位证一比一定(购)中央昆士兰大学毕业证(CQU毕业证)成绩单学位证
一比一定(购)中央昆士兰大学毕业证(CQU毕业证)成绩单学位证eqaqen
 
Specialize in a MSc within Biomanufacturing, and work part-time as Process En...
Specialize in a MSc within Biomanufacturing, and work part-time as Process En...Specialize in a MSc within Biomanufacturing, and work part-time as Process En...
Specialize in a MSc within Biomanufacturing, and work part-time as Process En...Juli Boned
 
Brand Analysis for reggaeton artist Jahzel.
Brand Analysis for reggaeton artist Jahzel.Brand Analysis for reggaeton artist Jahzel.
Brand Analysis for reggaeton artist Jahzel.GabrielaMiletti
 
Vip Malegaon Escorts Service Girl ^ 9332606886, WhatsApp Anytime Malegaon
Vip Malegaon Escorts Service Girl ^ 9332606886, WhatsApp Anytime MalegaonVip Malegaon Escorts Service Girl ^ 9332606886, WhatsApp Anytime Malegaon
Vip Malegaon Escorts Service Girl ^ 9332606886, WhatsApp Anytime Malegaonmeghakumariji156
 
7737669865 Call Girls In Ahmedabad Escort Service Available 24×7 In In Ahmedabad
7737669865 Call Girls In Ahmedabad Escort Service Available 24×7 In In Ahmedabad7737669865 Call Girls In Ahmedabad Escort Service Available 24×7 In In Ahmedabad
7737669865 Call Girls In Ahmedabad Escort Service Available 24×7 In In Ahmedabadgargpaaro
 
K Venkat Naveen Kumar | GCP Data Engineer | CV
K Venkat Naveen Kumar | GCP Data Engineer | CVK Venkat Naveen Kumar | GCP Data Engineer | CV
K Venkat Naveen Kumar | GCP Data Engineer | CVK VENKAT NAVEEN KUMAR
 

Dernier (20)

Miletti Gabriela_Vision Plan for artist Jahzel.pdf
Miletti Gabriela_Vision Plan for artist Jahzel.pdfMiletti Gabriela_Vision Plan for artist Jahzel.pdf
Miletti Gabriela_Vision Plan for artist Jahzel.pdf
 
drug book file on obs. and gynae clinical pstings
drug book file on obs. and gynae clinical pstingsdrug book file on obs. and gynae clinical pstings
drug book file on obs. and gynae clinical pstings
 
Top profile Call Girls In Shivamogga [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Shivamogga [ 7014168258 ] Call Me For Genuine Model...Top profile Call Girls In Shivamogga [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Shivamogga [ 7014168258 ] Call Me For Genuine Model...
 
Top profile Call Girls In Jabalpur [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Jabalpur [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Jabalpur [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Jabalpur [ 7014168258 ] Call Me For Genuine Models ...
 
Top profile Call Girls In Shillong [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Shillong [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Shillong [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Shillong [ 7014168258 ] Call Me For Genuine Models ...
 
怎样办理哥伦比亚大学毕业证(Columbia毕业证书)成绩单学校原版复制
怎样办理哥伦比亚大学毕业证(Columbia毕业证书)成绩单学校原版复制怎样办理哥伦比亚大学毕业证(Columbia毕业证书)成绩单学校原版复制
怎样办理哥伦比亚大学毕业证(Columbia毕业证书)成绩单学校原版复制
 
Personal Brand Exploration ppt.- Ronnie Jones
Personal Brand  Exploration ppt.- Ronnie JonesPersonal Brand  Exploration ppt.- Ronnie Jones
Personal Brand Exploration ppt.- Ronnie Jones
 
<DUBAI>Abortion pills IN UAE {{+971561686603*^Mifepristone & Misoprostol in D...
<DUBAI>Abortion pills IN UAE {{+971561686603*^Mifepristone & Misoprostol in D...<DUBAI>Abortion pills IN UAE {{+971561686603*^Mifepristone & Misoprostol in D...
<DUBAI>Abortion pills IN UAE {{+971561686603*^Mifepristone & Misoprostol in D...
 
Top profile Call Girls In Ratnagiri [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Ratnagiri [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Ratnagiri [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Ratnagiri [ 7014168258 ] Call Me For Genuine Models...
 
B.tech Civil Engineering Major Project by Deepak Kumar ppt.pdf
B.tech Civil Engineering Major Project by Deepak Kumar ppt.pdfB.tech Civil Engineering Major Project by Deepak Kumar ppt.pdf
B.tech Civil Engineering Major Project by Deepak Kumar ppt.pdf
 
Top profile Call Girls In bhubaneswar [ 7014168258 ] Call Me For Genuine Mode...
Top profile Call Girls In bhubaneswar [ 7014168258 ] Call Me For Genuine Mode...Top profile Call Girls In bhubaneswar [ 7014168258 ] Call Me For Genuine Mode...
Top profile Call Girls In bhubaneswar [ 7014168258 ] Call Me For Genuine Mode...
 
Howrah [ Call Girls Kolkata ₹7.5k Pick Up & Drop With Cash Payment 8005736733...
Howrah [ Call Girls Kolkata ₹7.5k Pick Up & Drop With Cash Payment 8005736733...Howrah [ Call Girls Kolkata ₹7.5k Pick Up & Drop With Cash Payment 8005736733...
Howrah [ Call Girls Kolkata ₹7.5k Pick Up & Drop With Cash Payment 8005736733...
 
B.tech civil major project by Deepak Kumar
B.tech civil major project by Deepak KumarB.tech civil major project by Deepak Kumar
B.tech civil major project by Deepak Kumar
 
Top profile Call Girls In Sagar [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Sagar [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Sagar [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Sagar [ 7014168258 ] Call Me For Genuine Models We ...
 
一比一定(购)中央昆士兰大学毕业证(CQU毕业证)成绩单学位证
一比一定(购)中央昆士兰大学毕业证(CQU毕业证)成绩单学位证一比一定(购)中央昆士兰大学毕业证(CQU毕业证)成绩单学位证
一比一定(购)中央昆士兰大学毕业证(CQU毕业证)成绩单学位证
 
Specialize in a MSc within Biomanufacturing, and work part-time as Process En...
Specialize in a MSc within Biomanufacturing, and work part-time as Process En...Specialize in a MSc within Biomanufacturing, and work part-time as Process En...
Specialize in a MSc within Biomanufacturing, and work part-time as Process En...
 
Brand Analysis for reggaeton artist Jahzel.
Brand Analysis for reggaeton artist Jahzel.Brand Analysis for reggaeton artist Jahzel.
Brand Analysis for reggaeton artist Jahzel.
 
Vip Malegaon Escorts Service Girl ^ 9332606886, WhatsApp Anytime Malegaon
Vip Malegaon Escorts Service Girl ^ 9332606886, WhatsApp Anytime MalegaonVip Malegaon Escorts Service Girl ^ 9332606886, WhatsApp Anytime Malegaon
Vip Malegaon Escorts Service Girl ^ 9332606886, WhatsApp Anytime Malegaon
 
7737669865 Call Girls In Ahmedabad Escort Service Available 24×7 In In Ahmedabad
7737669865 Call Girls In Ahmedabad Escort Service Available 24×7 In In Ahmedabad7737669865 Call Girls In Ahmedabad Escort Service Available 24×7 In In Ahmedabad
7737669865 Call Girls In Ahmedabad Escort Service Available 24×7 In In Ahmedabad
 
K Venkat Naveen Kumar | GCP Data Engineer | CV
K Venkat Naveen Kumar | GCP Data Engineer | CVK Venkat Naveen Kumar | GCP Data Engineer | CV
K Venkat Naveen Kumar | GCP Data Engineer | CV
 

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