Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
GayleL.McDowell | Founder/ CEO
gayle in/gaylemcdgayle
Cracking the
Coding Interview
CareerCup
gayle in/gaylemcdgayleGayle Laakmann McDowell 2
Hi! I’m Gayle LaakmannMcDowell
Author Interview Coach Interview Consulting...
What We Look
For
Things that make you think
01
Gayle Laakmann McDowell 4gayle in/gaylemcdgayle
Why?
Analytical skills
How you think
Make tradeoffs
Pushthrough hard
p...
gayle in/gaylemcdgayle 5
z
Gayle Laakmann McDowell
What
is NOT
expected
To know the answers
To solve immediately
To cod...
gayle in/gaylemcdgayle 6
z
Gayle Laakmann McDowell
What
IS
expected
Be excitedabout hard problems
Drive!
 Keep trying w...
Preparation
02
gayle in/gaylemcdgayleGayle Laakmann McDowell 8
Essential Knowledge
Data Structures Algorithms Concepts
ArrayLists Merge S...
gayle in/gaylemcdgayleGayle Laakmann McDowell 9
Preparation
MASTER Big O
ImplementDS/Algorithms
Practicewith interview ...
7 Steps
Things that make you think
03
gayle in/gaylemcdgayle 11
z
Gayle Laakmann McDowell
How
To
Approach
CrackingTheCodingInterview.com“Resources”
gayle in/gaylemcdgayle 12Gayle Laakmann McDowell
step
Listen (for clues)
gayle in/gaylemcdgayle 13Gayle Laakmann McDowell
step
Draw an Example
INTERSECTION SIZE: Find #
elementsin common between...
gayle in/gaylemcdgayleGayle Laakmann McDowell 14
Ex:Intersection ofTwo Sorted Arrays
Most people draw somethinglike this:...
gayle in/gaylemcdgayleGayle Laakmann McDowell 15
Ex:Intersection ofTwo Sorted Arrays
Better:
[1, 12, 15, 19, 20, 21]
[2, ...
gayle in/gaylemcdgayle 16Gayle Laakmann McDowell
step
Draw an Example
Big Enough
General Purpose
+
gayle in/gaylemcdgayle 17Gayle Laakmann McDowell
step
Brute Force / Naive
Stupid&terribleisokay!
gayle in/gaylemcdgayle 18Gayle Laakmann McDowell
step
Optimize
Walk through brute
force
Look for optimizations
Gayle Laakmann McDowell 19gayle in/gaylemcdgayle
Techniquesto Develop Algorithms
BUD
Space andTime
Do It Yourself
Gayle Laakmann McDowell 20gayle in/gaylemcdgayle
(A) Look for BUD
Bottlenecks
Unnecessary work
Duplicated work
Gayle Laakmann McDowell 21gayle in/gaylemcdgayle
What’s the bottleneck?
 Ex: countingthe intersection
[1, 12, 15, 19, 20,...
Gayle Laakmann McDowell 22gayle in/gaylemcdgayle
What’s unnecessary?
 Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000
 Unnec...
Gayle Laakmann McDowell 23gayle in/gaylemcdgayle
What’s unnecessary?
 Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000
 Unnec...
Gayle Laakmann McDowell 24gayle in/gaylemcdgayle
What’s duplicated?
 Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000
 Duplic...
Gayle Laakmann McDowell 25gayle in/gaylemcdgayle
What’s duplicated?
 Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000
 Duplic...
Gayle Laakmann McDowell 26gayle in/gaylemcdgayle
What’s duplicated?
 Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000
 Duplic...
Gayle Laakmann McDowell 27gayle in/gaylemcdgayle
What’s duplicated?
 Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000
D
Gayle Laakmann McDowell 28gayle in/gaylemcdgayle
(B)Space/TimeTradeoffs
Hashtables & other datastructures
Precomputing
Gayle Laakmann McDowell 29gayle in/gaylemcdgayle
(C)Do it yourself
Findpermutationsof swithinb
gayle in/gaylemcdgayleGayle Laakmann McDowell 30
find abbcd in
b a b c d b a e f d b b a c b d d f a e
0 1 2 3 4 5 6 7 8 9...
Gayle Laakmann McDowell 31gayle in/gaylemcdgayle
(C)Do it yourself
Findpermutationsof swithinb
 s = abbcd
 b =
Findthe...
Gayle Laakmann McDowell 32gayle in/gaylemcdgayle
Techniquesto Develop Algorithms
BUD
Space and Time
Do It Yourself
gayle in/gaylemcdgayle 33Gayle Laakmann McDowell
step
Walk Through
Know the variables
andwhen they change
gayle in/gaylemcdgayle 34Gayle Laakmann McDowell
step
Write Beautiful Code
Gayle Laakmann McDowell 35gayle in/gaylemcdgayle
How toWrite WhiteboardCode
Top-leftcorner
Short Hand Helps
Good style
...
Gayle Laakmann McDowell 36gayle in/gaylemcdgayle
ShortHandHelps
Good:
Good Enough &Easier:
gayle in/gaylemcdgayleGayle Laakmann McDowell 37
Good Style
Appropriate & ConsistentSpacing
Good Variable Names
BAD
gayle in/gaylemcdgayleGayle Laakmann McDowell 38
Modularization
gayle in/gaylemcdgayle 39Gayle Laakmann McDowell
step
Testing
FIRST Analyze
 What’s it doing? Why?
 Anything that looks...
gayle in/gaylemcdgayle 40
z
Gayle Laakmann McDowell
How
To
Approach
CrackingTheCodingInterview.com“Resources”
If you forget
everything else
Please remember this
04
gayle in/gaylemcdgayleGayle Laakmann McDowell 42
Please please please please
Create example
 Big (tinyisuseless)
 Gener...
gayle in/gaylemcdgayleGayle Laakmann McDowell 43
Other Resources
Gayle.com
CareerCup.com
CrackingThe
CodingInterview.com
O...
Upcoming SlideShare
Loading in …5
×

Cracking the Coding Interview - 7 steps - Udacity

3,201 views

Published on

7 steps to tackling a coding problem

Published in: Career
  • Hello! Get Your Professional Job-Winning Resume Here - Check our website! https://vk.cc/818RFv
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Cracking the Coding Interview - 7 steps - Udacity

  1. 1. GayleL.McDowell | Founder/ CEO gayle in/gaylemcdgayle Cracking the Coding Interview CareerCup
  2. 2. gayle in/gaylemcdgayleGayle Laakmann McDowell 2 Hi! I’m Gayle LaakmannMcDowell Author Interview Coach Interview Consulting <dev> </dev> (CS) (MBA)
  3. 3. What We Look For Things that make you think 01
  4. 4. Gayle Laakmann McDowell 4gayle in/gaylemcdgayle Why? Analytical skills How you think Make tradeoffs Pushthrough hard problems Communication Strong CS fundamentals
  5. 5. gayle in/gaylemcdgayle 5 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.
  6. 6. gayle in/gaylemcdgayle 6 z Gayle Laakmann McDowell What IS expected Be excitedabout hard problems Drive!  Keep trying when stuck  More than just “correct” Pay attention to me! Write real code Showmehowyouthink!
  7. 7. Preparation 02
  8. 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) & Graphs Breadth-FirstSearch Recursion LinkedLists Depth-FirstSearch Memoization/ Dynamic Programming Stacks/ Queues BinarySearch Heaps
  9. 9. gayle in/gaylemcdgayleGayle Laakmann McDowell 9 Preparation MASTER Big O ImplementDS/Algorithms Practicewith interview questions Code on paper/whiteboard Mock interviews PUSHYOURSELF!
  10. 10. 7 Steps Things that make you think 03
  11. 11. gayle in/gaylemcdgayle 11 z Gayle Laakmann McDowell How To Approach CrackingTheCodingInterview.com“Resources”
  12. 12. gayle in/gaylemcdgayle 12Gayle Laakmann McDowell step Listen (for clues)
  13. 13. gayle in/gaylemcdgayle 13Gayle Laakmann McDowell step Draw an Example INTERSECTION SIZE: Find # elementsin common between two sorted, distinct arrays:
  14. 14. gayle in/gaylemcdgayleGayle Laakmann McDowell 14 Ex:Intersection ofTwo Sorted Arrays Most people draw somethinglike this: [1, 12, 15, 19] [2, 12, 13, 20]  Toosmall  Toospecial-case-y • same size, one commonelement, same index
  15. 15. gayle in/gaylemcdgayleGayle Laakmann McDowell 15 Ex:Intersection ofTwo Sorted Arrays Better: [1, 12, 15, 19, 20, 21] [2, 15, 17, 19, 21, 25, 27]  Big  No specialcases
  16. 16. gayle in/gaylemcdgayle 16Gayle Laakmann McDowell step Draw an Example Big Enough General Purpose +
  17. 17. gayle in/gaylemcdgayle 17Gayle Laakmann McDowell step Brute Force / Naive Stupid&terribleisokay!
  18. 18. gayle in/gaylemcdgayle 18Gayle Laakmann McDowell step Optimize Walk through brute force Look for optimizations
  19. 19. Gayle Laakmann McDowell 19gayle in/gaylemcdgayle Techniquesto Develop Algorithms BUD Space andTime Do It Yourself
  20. 20. Gayle Laakmann McDowell 20gayle in/gaylemcdgayle (A) Look for BUD Bottlenecks Unnecessary work Duplicated work
  21. 21. Gayle Laakmann McDowell 21gayle in/gaylemcdgayle What’s the bottleneck?  Ex: countingthe intersection [1, 12, 15, 19, 20, 21] [2, 15, 17, 19, 21, 25, 27]  Brute Force: O(A * B)   Bottleneck:O(B) tosearch  Binary Search Algorithm: O(A log B)   Bottleneck:O(logB)tosearch  Sorted Merge: O(A + B) B
  22. 22. 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
  23. 23. 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
  24. 24. 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
  25. 25. 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 29855 4 32 32832 4 33 36001 … … … 5 59 205504 5 60 216125 5 61 227106 … … …
  26. 26. 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) … …
  27. 27. Gayle Laakmann McDowell 27gayle in/gaylemcdgayle What’s duplicated?  Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000 D
  28. 28. Gayle Laakmann McDowell 28gayle in/gaylemcdgayle (B)Space/TimeTradeoffs Hashtables & other datastructures Precomputing
  29. 29. Gayle Laakmann McDowell 29gayle in/gaylemcdgayle (C)Do it yourself Findpermutationsof swithinb
  30. 30. gayle in/gaylemcdgayleGayle Laakmann McDowell 30 find abbcd in b a b c d b a e f d b b a c b d d f a e 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
  31. 31. Gayle Laakmann McDowell 31gayle in/gaylemcdgayle (C)Do it yourself Findpermutationsof swithinb  s = abbcd  b = Findthem!  … now how didyou actuallydoit? b a b c d b a e f d b b a c b d d f a e
  32. 32. Gayle Laakmann McDowell 32gayle in/gaylemcdgayle Techniquesto Develop Algorithms BUD Space and Time Do It Yourself
  33. 33. gayle in/gaylemcdgayle 33Gayle Laakmann McDowell step Walk Through Know the variables andwhen they change
  34. 34. gayle in/gaylemcdgayle 34Gayle Laakmann McDowell step Write Beautiful Code
  35. 35. Gayle Laakmann McDowell 35gayle in/gaylemcdgayle How toWrite WhiteboardCode Top-leftcorner Short Hand Helps Good style Modularize (upfront!)
  36. 36. Gayle Laakmann McDowell 36gayle in/gaylemcdgayle ShortHandHelps Good: Good Enough &Easier:
  37. 37. gayle in/gaylemcdgayleGayle Laakmann McDowell 37 Good Style Appropriate & ConsistentSpacing Good Variable Names BAD
  38. 38. gayle in/gaylemcdgayleGayle Laakmann McDowell 38 Modularization
  39. 39. gayle in/gaylemcdgayle 39Gayle Laakmann McDowell step Testing FIRST Analyze  What’s it doing? Why?  Anything that looks weird?  Errorhot spots THEN use test cases  Small test cases  Edge cases  Biggertest cases BUT…  Test code, notalgorithm  Think as you test  Think before you fix
  40. 40. gayle in/gaylemcdgayle 40 z Gayle Laakmann McDowell How To Approach CrackingTheCodingInterview.com“Resources”
  41. 41. If you forget everything else Please remember this 04
  42. 42. gayle in/gaylemcdgayleGayle Laakmann McDowell 42 Please please please please Create example  Big (tinyisuseless)  Generic(nota specialcase) Walkthrough it  Figureouttheoutputforthatoneinput  (Don’tworryaboutalgorithms/ implementation) DO NOT CODE UNTIL YOU’RE READY  100%surethatyouknowwhatyou’redoing  100%surethatyourinterviewwantsyoutocode
  43. 43. gayle in/gaylemcdgayleGayle Laakmann McDowell 43 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

×