SlideShare a Scribd company logo
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
Ad

Recommended

Cracking the Coding Interview - 7 steps - Udacity
Cracking the Coding Interview - 7 steps - Udacity
Gayle McDowell
 
Clean Code
Clean Code
swaraj Patil
 
Clean code
Clean code
ifnu bima
 
From Query Plan to Query Performance: Supercharging your Apache Spark Queries...
From Query Plan to Query Performance: Supercharging your Apache Spark Queries...
Databricks
 
Clean code
Clean code
Achintya Kumar
 
MongoDB World 2019: The Sights (and Smells) of a Bad Query
MongoDB World 2019: The Sights (and Smells) of a Bad Query
MongoDB
 
C++ Unit Test with Google Testing Framework
C++ Unit Test with Google Testing Framework
Humberto Marchezi
 
Trees In The Database - Advanced data structures
Trees In The Database - Advanced data structures
Lorenzo Alberton
 
Clean Code I - Best Practices
Clean Code I - Best Practices
Theo Jungeblut
 
Rule Engine & Drools
Rule Engine & Drools
Sandip Jadhav
 
Clean code
Clean code
Arturo Herrero
 
Oracle Client Failover - Under The Hood
Oracle Client Failover - Under The Hood
Ludovico Caldara
 
Validate Your Validations: Both Sides Now
Validate Your Validations: Both Sides Now
Karen Cannell
 
Clean code
Clean code
Mahmoud Zizo
 
Cassandra
Cassandra
Edureka!
 
Real-time Analytics with Trino and Apache Pinot
Real-time Analytics with Trino and Apache Pinot
Xiang Fu
 
Models for hierarchical data
Models for hierarchical data
Karwin Software Solutions LLC
 
MongoDB .local Toronto 2019: Tips and Tricks for Effective Indexing
MongoDB .local Toronto 2019: Tips and Tricks for Effective Indexing
MongoDB
 
Clean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a Monolith
Victor Rentea
 
Clean code: meaningful Name
Clean code: meaningful Name
nahid035
 
ProxySQL High Availability (Clustering)
ProxySQL High Availability (Clustering)
Mydbops
 
Sql Antipatterns Strike Back
Sql Antipatterns Strike Back
Karwin Software Solutions LLC
 
Elixir Programming Language 101
Elixir Programming Language 101
Around25
 
MongoDB .local Toronto 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pi...
MongoDB .local Toronto 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pi...
MongoDB
 
NIO and NIO2
NIO and NIO2
Balamurugan Soundararajan
 
테스터가 말하는 테스트코드 작성 팁과 사례
테스터가 말하는 테스트코드 작성 팁과 사례
SangIn Choung
 
Recursive Query Throwdown
Recursive Query Throwdown
Karwin Software Solutions LLC
 
Cloud Native Java GraalVM 이상과 현실
Cloud Native Java GraalVM 이상과 현실
Taewan Kim
 
Cracking the Coding interview (Abbreviated) - aug 2016
Cracking the Coding interview (Abbreviated) - aug 2016
Gayle McDowell
 
Cracking the Facebook Coding Interview
Cracking the Facebook Coding Interview
Gayle McDowell
 

More Related Content

What's hot (20)

Clean Code I - Best Practices
Clean Code I - Best Practices
Theo Jungeblut
 
Rule Engine & Drools
Rule Engine & Drools
Sandip Jadhav
 
Clean code
Clean code
Arturo Herrero
 
Oracle Client Failover - Under The Hood
Oracle Client Failover - Under The Hood
Ludovico Caldara
 
Validate Your Validations: Both Sides Now
Validate Your Validations: Both Sides Now
Karen Cannell
 
Clean code
Clean code
Mahmoud Zizo
 
Cassandra
Cassandra
Edureka!
 
Real-time Analytics with Trino and Apache Pinot
Real-time Analytics with Trino and Apache Pinot
Xiang Fu
 
Models for hierarchical data
Models for hierarchical data
Karwin Software Solutions LLC
 
MongoDB .local Toronto 2019: Tips and Tricks for Effective Indexing
MongoDB .local Toronto 2019: Tips and Tricks for Effective Indexing
MongoDB
 
Clean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a Monolith
Victor Rentea
 
Clean code: meaningful Name
Clean code: meaningful Name
nahid035
 
ProxySQL High Availability (Clustering)
ProxySQL High Availability (Clustering)
Mydbops
 
Sql Antipatterns Strike Back
Sql Antipatterns Strike Back
Karwin Software Solutions LLC
 
Elixir Programming Language 101
Elixir Programming Language 101
Around25
 
MongoDB .local Toronto 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pi...
MongoDB .local Toronto 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pi...
MongoDB
 
NIO and NIO2
NIO and NIO2
Balamurugan Soundararajan
 
테스터가 말하는 테스트코드 작성 팁과 사례
테스터가 말하는 테스트코드 작성 팁과 사례
SangIn Choung
 
Recursive Query Throwdown
Recursive Query Throwdown
Karwin Software Solutions LLC
 
Cloud Native Java GraalVM 이상과 현실
Cloud Native Java GraalVM 이상과 현실
Taewan Kim
 
Clean Code I - Best Practices
Clean Code I - Best Practices
Theo Jungeblut
 
Rule Engine & Drools
Rule Engine & Drools
Sandip Jadhav
 
Oracle Client Failover - Under The Hood
Oracle Client Failover - Under The Hood
Ludovico Caldara
 
Validate Your Validations: Both Sides Now
Validate Your Validations: Both Sides Now
Karen Cannell
 
Real-time Analytics with Trino and Apache Pinot
Real-time Analytics with Trino and Apache Pinot
Xiang Fu
 
MongoDB .local Toronto 2019: Tips and Tricks for Effective Indexing
MongoDB .local Toronto 2019: Tips and Tricks for Effective Indexing
MongoDB
 
Clean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a Monolith
Victor Rentea
 
Clean code: meaningful Name
Clean code: meaningful Name
nahid035
 
ProxySQL High Availability (Clustering)
ProxySQL High Availability (Clustering)
Mydbops
 
Elixir Programming Language 101
Elixir Programming Language 101
Around25
 
MongoDB .local Toronto 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pi...
MongoDB .local Toronto 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pi...
MongoDB
 
테스터가 말하는 테스트코드 작성 팁과 사례
테스터가 말하는 테스트코드 작성 팁과 사례
SangIn Choung
 
Cloud Native Java GraalVM 이상과 현실
Cloud Native Java GraalVM 이상과 현실
Taewan Kim
 

Similar to Cracking the Algorithm & Coding Interview (10)

Cracking the Coding interview (Abbreviated) - aug 2016
Cracking the Coding interview (Abbreviated) - aug 2016
Gayle McDowell
 
Cracking the Facebook Coding Interview
Cracking the Facebook Coding Interview
Gayle McDowell
 
Cracking the Coding interview (College)
Cracking the Coding interview (College)
Gayle McDowell
 
How to Hire Software Engineers: Best and Worst Practices
How to Hire Software Engineers: Best and Worst Practices
Gayle McDowell
 
Prepping Your Engineering Candidates to Reduce Your False Negatives
Prepping Your Engineering Candidates to Reduce Your False Negatives
Gayle McDowell
 
Gayle Laakmann McDowell - Talent42 2015
Gayle Laakmann McDowell - Talent42 2015
Talent42
 
How to Interview Like Google (But Better) - SVCC
How to Interview Like Google (But Better) - SVCC
Gayle McDowell
 
Cracking the PM Interview
Cracking the PM Interview
Gayle McDowell
 
Math Gr4 Ch12
Math Gr4 Ch12
madterrell
 
Math Gr4 Ch12
Math Gr4 Ch12
madterrell
 
Cracking the Coding interview (Abbreviated) - aug 2016
Cracking the Coding interview (Abbreviated) - aug 2016
Gayle McDowell
 
Cracking the Facebook Coding Interview
Cracking the Facebook Coding Interview
Gayle McDowell
 
Cracking the Coding interview (College)
Cracking the Coding interview (College)
Gayle McDowell
 
How to Hire Software Engineers: Best and Worst Practices
How to Hire Software Engineers: Best and Worst Practices
Gayle McDowell
 
Prepping Your Engineering Candidates to Reduce Your False Negatives
Prepping Your Engineering Candidates to Reduce Your False Negatives
Gayle McDowell
 
Gayle Laakmann McDowell - Talent42 2015
Gayle Laakmann McDowell - Talent42 2015
Talent42
 
How to Interview Like Google (But Better) - SVCC
How to Interview Like Google (But Better) - SVCC
Gayle McDowell
 
Cracking the PM Interview
Cracking the PM Interview
Gayle McDowell
 
Ad

More from Gayle McDowell (12)

Architecture of Tech Interviews
Architecture of Tech Interviews
Gayle McDowell
 
Cracking the PM Interview
Cracking the PM Interview
Gayle McDowell
 
Cracking the Product Manager Interview
Cracking the Product Manager Interview
Gayle McDowell
 
Cracking the Interview Skills (Coding, Soft Skills, Product Management) Handouts
Cracking the Interview Skills (Coding, Soft Skills, Product Management) Handouts
Gayle McDowell
 
Creating the (Im)perfect Developer Interview
Creating the (Im)perfect Developer Interview
Gayle McDowell
 
Hiring Great Product Managers
Hiring Great Product Managers
Gayle McDowell
 
Cracking the Product Manager Interview
Cracking the Product Manager Interview
Gayle McDowell
 
Cracking the Coding Interview
Cracking the Coding Interview
Gayle McDowell
 
Reverse Engineering Engineering Interviewing: How to Be a Great Interviewer
Reverse Engineering Engineering Interviewing: How to Be a Great Interviewer
Gayle McDowell
 
Transitioning from Engineering to Product Management
Transitioning from Engineering to Product Management
Gayle McDowell
 
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)
Gayle McDowell
 
Architecture of Tech Interviews
Architecture of Tech Interviews
Gayle McDowell
 
Cracking the PM Interview
Cracking the PM Interview
Gayle McDowell
 
Cracking the Product Manager Interview
Cracking the Product Manager Interview
Gayle McDowell
 
Cracking the Interview Skills (Coding, Soft Skills, Product Management) Handouts
Cracking the Interview Skills (Coding, Soft Skills, Product Management) Handouts
Gayle McDowell
 
Creating the (Im)perfect Developer Interview
Creating the (Im)perfect Developer Interview
Gayle McDowell
 
Hiring Great Product Managers
Hiring Great Product Managers
Gayle McDowell
 
Cracking the Product Manager Interview
Cracking the Product Manager Interview
Gayle McDowell
 
Cracking the Coding Interview
Cracking the Coding Interview
Gayle McDowell
 
Reverse Engineering Engineering Interviewing: How to Be a Great Interviewer
Reverse Engineering Engineering Interviewing: How to Be a Great Interviewer
Gayle McDowell
 
Transitioning from Engineering to Product Management
Transitioning from Engineering to Product Management
Gayle McDowell
 
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)
Gayle McDowell
 
Ad

Recently uploaded (20)

Presentation about the current products.pptx
Presentation about the current products.pptx
ikrammustafa51
 
Twilio Jobs Ghaziabad 673 Part Time Job in Uttar Pradesh.pdf
Twilio Jobs Ghaziabad 673 Part Time Job in Uttar Pradesh.pdf
infonaukridekhe
 
IISc-CDS-v2xxxxxxxxxxxxxcxxxxxx (1).potx
IISc-CDS-v2xxxxxxxxxxxxxcxxxxxx (1).potx
rnkaushal2
 
Current Affairs for Prelims (Schemes) 2024 (1).pptx
Current Affairs for Prelims (Schemes) 2024 (1).pptx
malavikasprinklr
 
ACEN presentation / huddle from June 2025
ACEN presentation / huddle from June 2025
Mark Rauterkus
 
merged_presentation_choladeck (1).pptx h
merged_presentation_choladeck (1).pptx h
sukh27012
 
CISA Certification And Training online..
CISA Certification And Training online..
Streling next pvt ltd
 
PEACH Jobs Board - (Updated on June 12th)
PEACH Jobs Board - (Updated on June 12th)
PEACHOrgnization
 
Expection Setting-1st ppt-Reshma.pdfjjkk
Expection Setting-1st ppt-Reshma.pdfjjkk
Jeevan900623
 
Curriculum Vitae of Professor Dr. Nazrul Islam
Curriculum Vitae of Professor Dr. Nazrul Islam
Dr. Nazrul Islam
 
A Guide for a Winning Interview June 2025
A Guide for a Winning Interview June 2025
Bruce Bennett
 
SOC_Incident_Report_Process_Presentation.pptx
SOC_Incident_Report_Process_Presentation.pptx
rtanvi1518
 
最新版美国埃默里大学毕业证(Emory毕业证书)原版定制
最新版美国埃默里大学毕业证(Emory毕业证书)原版定制
Taqyea
 
Interviewing Techniques updated version.ppt
Interviewing Techniques updated version.ppt
mandiikkj
 
最新版西班牙拉古纳大学毕业证(ULL毕业证书)原版定制
最新版西班牙拉古纳大学毕业证(ULL毕业证书)原版定制
Taqyea
 
How to Become a CPA USA and Boost Your Career
How to Become a CPA USA and Boost Your Career
ipfcadwords
 
Garments Manufacturing, design, cutting and sewing of garments
Garments Manufacturing, design, cutting and sewing of garments
NaumanRafique9
 
What is UPSC job in India ? , Details about UPSC
What is UPSC job in India ? , Details about UPSC
prathamdigitalmarket
 
2025 English CV Sigve Hamilton Aspelund.docx
2025 English CV Sigve Hamilton Aspelund.docx
Sigve Hamilton Aspelund
 
Bbhuiiiugtuuuhhhhhhhhhhhhhhhhhhhhhhhhhhh
Bbhuiiiugtuuuhhhhhhhhhhhhhhhhhhhhhhhhhhh
HifzaNadeem5
 
Presentation about the current products.pptx
Presentation about the current products.pptx
ikrammustafa51
 
Twilio Jobs Ghaziabad 673 Part Time Job in Uttar Pradesh.pdf
Twilio Jobs Ghaziabad 673 Part Time Job in Uttar Pradesh.pdf
infonaukridekhe
 
IISc-CDS-v2xxxxxxxxxxxxxcxxxxxx (1).potx
IISc-CDS-v2xxxxxxxxxxxxxcxxxxxx (1).potx
rnkaushal2
 
Current Affairs for Prelims (Schemes) 2024 (1).pptx
Current Affairs for Prelims (Schemes) 2024 (1).pptx
malavikasprinklr
 
ACEN presentation / huddle from June 2025
ACEN presentation / huddle from June 2025
Mark Rauterkus
 
merged_presentation_choladeck (1).pptx h
merged_presentation_choladeck (1).pptx h
sukh27012
 
CISA Certification And Training online..
CISA Certification And Training online..
Streling next pvt ltd
 
PEACH Jobs Board - (Updated on June 12th)
PEACH Jobs Board - (Updated on June 12th)
PEACHOrgnization
 
Expection Setting-1st ppt-Reshma.pdfjjkk
Expection Setting-1st ppt-Reshma.pdfjjkk
Jeevan900623
 
Curriculum Vitae of Professor Dr. Nazrul Islam
Curriculum Vitae of Professor Dr. Nazrul Islam
Dr. Nazrul Islam
 
A Guide for a Winning Interview June 2025
A Guide for a Winning Interview June 2025
Bruce Bennett
 
SOC_Incident_Report_Process_Presentation.pptx
SOC_Incident_Report_Process_Presentation.pptx
rtanvi1518
 
最新版美国埃默里大学毕业证(Emory毕业证书)原版定制
最新版美国埃默里大学毕业证(Emory毕业证书)原版定制
Taqyea
 
Interviewing Techniques updated version.ppt
Interviewing Techniques updated version.ppt
mandiikkj
 
最新版西班牙拉古纳大学毕业证(ULL毕业证书)原版定制
最新版西班牙拉古纳大学毕业证(ULL毕业证书)原版定制
Taqyea
 
How to Become a CPA USA and Boost Your Career
How to Become a CPA USA and Boost Your Career
ipfcadwords
 
Garments Manufacturing, design, cutting and sewing of garments
Garments Manufacturing, design, cutting and sewing of garments
NaumanRafique9
 
What is UPSC job in India ? , Details about UPSC
What is UPSC job in India ? , Details about UPSC
prathamdigitalmarket
 
2025 English CV Sigve Hamilton Aspelund.docx
2025 English CV Sigve Hamilton Aspelund.docx
Sigve Hamilton Aspelund
 
Bbhuiiiugtuuuhhhhhhhhhhhhhhhhhhhhhhhhhhh
Bbhuiiiugtuuuhhhhhhhhhhhhhhhhhhhhhhhhhhh
HifzaNadeem5
 

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 • [email protected] • quora.com