cracking the coding interview - 7 steps - udacity
TRANSCRIPT
![Page 1: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/1.jpg)
Gayle L.McDowell | Founder / CEO
gayle in/gaylemcdgayle
Cracking theCoding Interview
CareerCup
![Page 2: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/2.jpg)
gayle in/gaylemcdgayleGayle Laakmann McDowell 2
Hi! I’m Gayle Laakmann McDowell
Author Interview Coach Interview Consulting
<dev>
</dev>
(CS)
(MBA)
![Page 3: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/3.jpg)
What We Look ForThings that make you think01
![Page 4: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/4.jpg)
Gayle Laakmann McDowell 4gayle in/gaylemcdgayle
Why?
Analytical skills
How you think Make
tradeoffs
Push through hard problems
Communication Strong CS
fundamentals
![Page 5: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/5.jpg)
gayle in/gaylemcdgayle 5
z
Gayle Laakmann McDowell
Whatis NOT
expected
To know the answers To solve immediately To code perfectly
(It’s nice. It just doesn’t
happen*.)
* Okay fine. It happened once, in 2000+ hiring packets.
![Page 6: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/6.jpg)
gayle in/gaylemcdgayle 6
z
Gayle Laakmann McDowell
WhatIS
expected
Be excited about hard problems
Drive! Keep trying when stuck More than just “correct”
Pay attention to me! Write real code
Show me how you think!
![Page 7: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/7.jpg)
Preparation02
![Page 8: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/8.jpg)
gayle in/gaylemcdgayleGayle Laakmann McDowell 8
Essential KnowledgeData Structures
Algorithms Concepts
ArrayLists Merge Sort Big O Time
Hash Tables Quick Sort Big O Space
Trees (+ Tries) & Graphs
Breadth-First Search
Recursion
Linked Lists Depth-First Search
Memoization / Dynamic Programming
Stacks / Queues Binary Search
Heaps
![Page 9: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/9.jpg)
gayle in/gaylemcdgayleGayle Laakmann McDowell 9
Preparation
MASTER Big O Implement DS/Algorithms Practice with interview questions Code on paper/whiteboard Mock interviews
PUSH YOURSELF!
![Page 10: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/10.jpg)
7 StepsThings that make you think03
![Page 11: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/11.jpg)
gayle in/gaylemcdgayle 11
z
Gayle Laakmann McDowell
HowTo
Approach
Crac
king
TheC
odin
gInt
ervi
ew.c
om
“R
esou
rces
”
![Page 12: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/12.jpg)
gayle in/gaylemcdgayle 12Gayle Laakmann McDowell
step
1Listen (for clues)
![Page 13: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/13.jpg)
gayle in/gaylemcdgayle 13Gayle Laakmann McDowell
step
2Draw an Example INTERSECTION SIZE:
Find # elements in common between two sorted, distinct arrays:
![Page 14: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/14.jpg)
gayle in/gaylemcdgayleGayle Laakmann McDowell 14
Ex: Intersection of Two Sorted Arrays
Most people draw something like this:
[1, 12, 15, 19][2, 12, 13, 20]
Too small Too special-case-y • same size, one common element, same
index
![Page 15: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/15.jpg)
gayle in/gaylemcdgayleGayle Laakmann McDowell 15
Ex: Intersection of Two Sorted Arrays
Better:[1, 12, 15, 19, 20, 21][2, 15, 17, 19, 21, 25,
27] Big No special cases
![Page 16: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/16.jpg)
gayle in/gaylemcdgayle 16Gayle Laakmann McDowell
step
2Draw an Example
Big Enough
General Purpose
+
![Page 17: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/17.jpg)
gayle in/gaylemcdgayle 17Gayle Laakmann McDowell
step
3Brute Force / Naive
Stupid & terrible is okay!
![Page 18: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/18.jpg)
gayle in/gaylemcdgayle 18Gayle Laakmann McDowell
step
4Optimize
Walk through
brute force
Look for optimizations
![Page 19: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/19.jpg)
Gayle Laakmann McDowell 19gayle in/gaylemcdgayle
Techniques to Develop Algorithms
BUD Space and Time Do It Yourself
Push yourself!
![Page 20: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/20.jpg)
Gayle Laakmann McDowell 20gayle in/gaylemcdgayle
(A) Look for BUD
BottlenecksUnnecessary workDuplicated work
![Page 21: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/21.jpg)
Gayle Laakmann McDowell 21gayle in/gaylemcdgayle
What’s the bottleneck?
Ex: counting the intersection[1, 12, 15, 19, 20, 21][2, 15, 17, 19, 21, 25, 27]
Brute Force: O(A * B) Bottleneck: O(B) to search
Binary Search Algorithm: O(A log B) Bottleneck: O(log B) to search
Sorted Merge: O(A + B) B
![Page 22: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/22.jpg)
Gayle Laakmann McDowell 22gayle in/gaylemcdgayle
What’s unnecessary?
Ex: a3 + b3 = c3 + d3 (1 <= a, b, c, d <= 1000
Unnecessary: looking for d U
![Page 23: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/23.jpg)
Gayle Laakmann McDowell 23gayle in/gaylemcdgayle
What’s unnecessary?
Ex: a3 + b3 = c3 + d3 (1 <= a, b, c, d <= 1000
Unnecessary: looking for d U
![Page 24: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/24.jpg)
Gayle Laakmann McDowell 24gayle in/gaylemcdgayle
What’s duplicated?
Ex: a3 + b3 = c3 + d3 (1 <= a, b, c, d <= 1000
Duplicated: c, d pairs D
![Page 25: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/25.jpg)
Gayle Laakmann McDowell 25gayle in/gaylemcdgayle
What’s duplicated?
Ex: a3 + b3 = c3 + d3 (1 <= a, b, c, d <= 1000
Duplicated: c, d pairs D
c d c3 + d3
… … …4 31 298554 32 328324 33 36001… … …5 59 2055045 60 2161255 61 227106… … …
![Page 26: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/26.jpg)
Gayle Laakmann McDowell 26gayle in/gaylemcdgayle
What’s duplicated?
Ex: a3 + b3 = c3 + d3 (1 <= a, b, c, d <= 1000
Duplicated: c, d pairs D
c3 + d3 (c, d)… …29855 (4, 31)32832 (4, 32), (18, 30)36001 (4, 33)… …205504 (5, 59)216125 (5, 60), (45, 50)227106 (5, 61)… …
![Page 27: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/27.jpg)
Gayle Laakmann McDowell 27gayle in/gaylemcdgayle
What’s duplicated?
Ex: a3 + b3 = c3 + d3 (1 <= a, b, c, d <= 1000
D
![Page 28: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/28.jpg)
Gayle Laakmann McDowell 28gayle in/gaylemcdgayle
(B) Space/Time Tradeoffs
Hash tables & other data structures
Precomputing
![Page 29: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/29.jpg)
Gayle Laakmann McDowell 29gayle in/gaylemcdgayle
(C) Do it yourself
Find permutations of s within b
![Page 30: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/30.jpg)
gayle in/gaylemcdgayleGayle Laakmann McDowell 30
find abbcd inbabc dbaef dbbac bddf ae0 1 2 3 4 5 6 7 8 9 10 1
1 12 13 14 15 16 17 18 19
![Page 31: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/31.jpg)
Gayle Laakmann McDowell 31gayle in/gaylemcdgayle
(C) Do it yourself
Find permutations of s within b s = abbcd b =
Find them! … now how did you actually do it?
babc dbaef dbbac bddf ae
![Page 32: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/32.jpg)
Gayle Laakmann McDowell 32gayle in/gaylemcdgayle
Techniques to Develop Algorithms
BUD Space and Time Do It Yourself Push yourself!
![Page 33: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/33.jpg)
gayle in/gaylemcdgayle 33Gayle Laakmann McDowell
step
5Walk Through
Know the variablesand when they change
![Page 34: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/34.jpg)
gayle in/gaylemcdgayle 34Gayle Laakmann McDowell
step
6Write Beautiful Code
![Page 35: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/35.jpg)
Gayle Laakmann McDowell 35gayle in/gaylemcdgayle
How to Write Whiteboard Code
Top-left corner Short Hand
Helps
Good style Modularize
(upfront!)
![Page 36: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/36.jpg)
Gayle Laakmann McDowell 36gayle in/gaylemcdgayle
Short Hand Helps
Good:
Good Enough & Easier:
![Page 37: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/37.jpg)
gayle in/gaylemcdgayleGayle Laakmann McDowell 37
Good Style
Appropriate & Consistent Spacing
Good Variable NamesBAD
![Page 38: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/38.jpg)
gayle in/gaylemcdgayleGayle Laakmann McDowell 38
Modularization
![Page 39: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/39.jpg)
gayle in/gaylemcdgayle 39Gayle Laakmann McDowell
step
7Testing
FIRST Analyze What’s it doing? Why? Anything that looks
weird? Error hot spots
THEN use test cases Small test cases Edge cases Bigger test cases
BUT… Test code, not algorithm Think as you test Think before you fix
![Page 40: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/40.jpg)
gayle in/gaylemcdgayle 40
z
Gayle Laakmann McDowell
HowTo
Approach
Crac
king
TheC
odin
gInt
ervi
ew.c
om
“R
esou
rces
”
![Page 41: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/41.jpg)
If you forget everything elsePlease remember this04
![Page 42: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/42.jpg)
gayle in/gaylemcdgayleGayle Laakmann McDowell 42
Please please please please
Create example Big (tiny is useless) Generic (not a special case)
Walk through it Figure out the output for that one input (Don’t worry about algorithms /
implementation) DO NOT CODE UNTIL YOU’RE
READY 100% sure that you know what you’re
doing 100% sure that your interview wants you
to code
![Page 43: Cracking the Coding Interview - 7 steps - Udacity](https://reader033.vdocuments.net/reader033/viewer/2022042511/58cfa6911a28ab6b088b559f/html5/thumbnails/43.jpg)
gayle in/gaylemcdgayleGayle Laakmann McDowell 43
Other Resources
Gayle.com
CareerCup.com
CrackingTheCodingInterview.com
Or, follow me online • facebook.com/gayle• twitter.com/gayle• gayle.com• [email protected]• quora.com