GayleL. McDowell | Founder/ CEO
gayle in/gaylemcdgayle
Cracking the Coding
Interview
Harvard
CareerCup.com
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”
Early Preparation
Landing an interview
00
Gayle Laakmann McDowell 5gayle in/gaylemcdgayle
How to Get an Interview
Your Background
 Education
 Work Experience
 Projects
 Github/ OnlineProfile
Make a great resume
McDowell | CareerCup.com
Gayle Laakmann McDowell 6gayle in/gaylemcdgayle
Did I mention…
PROJECTS???
gayle in/gaylemcdgayle 7Gayle Laakmann McDowell
How We
Review
Resumes
1. Pull resume out of giant stack
2. Spot-check:
companies, projects, etc.
3. Skim bullets to see if you’ve written real
code.
4. Go tonextresume & whine abouthowmany
moreyouhaveleft.
InterviewReject
“Glancedat,”not
read.
15seconds
How CS ResumeShouldLook
Short
(1 – 2 line bullets)
3 – 4 Projects
Courses & independent
Finished or unfinished
List of Technical Skills
Short! Cut the “fluff.”
GPA if at least 3.0
max (in-major, overall)
One Page Only!
Unless > 10 years exp.
A Real Resume Format
with organized columns
Focus on Accomplishments
not responsibilities
Observe: No Objective!
Objectives / summaries
are almost always useless.
gayle in/gaylemcdgayle 9Gayle Laakmann McDowell
Talking
to
Recruiters
Show:
 What you’vedone(mobileapp?Show
it!)
 What you’reexcitedabout
Have a “pitch” ready
Weird is okay
 (arrogantisnot)
McDowell | CareerCup.com
Behavioral Questions
The soft squishy stuff.
gayle in/gaylemcdgayleGayle Laakmann McDowell 11
The Pitch /Resume Walk-Through
• Showsof success
• Prompt the
interviewer
• Hobbies
Gayle Laakmann McDowell 12gayle in/gaylemcdgayle
Your Past Work
 1 – 2 Hard Projects
 Hard/ cool
 Youwerecentral
 Technical depth
 All Past Work
 Challenges,architecture,
tradeoffs,mistakes,successes,
motivations
 Whatdid YOU do?
Technical
Questions
Why why why why why why meeeee
02
gayle in/gaylemcdgayle 14Gayle Laakmann McDowell
How
You’re
Judged
How did you do RELATIVE
to other candidates on
the SAME question?
… it’s about how quickly
you solved it relative to
other candidates.
It’s not about how
quickly you solved
the problem…
gayle in/gaylemcdgayle 15
z
Gayle Laakmann McDowell
What
Really
Happens
gayle in/gaylemcdgayle 16
z
Gayle Laakmann McDowell
What
Really
Happens
Knowledge Questions
 +Coding
Design/Scalability
 +Coding
Algorithms/Problem Solving
 +Coding
Knowledge Questions
How do indices work in SQL?
Gayle Laakmann McDowell 18gayle in/gaylemcdgayle
Knowledge Questions
If you list it, know it If you don’t know it,
admit it
 Deriveitifpossible.
Design
How would you design TinyURL?
gayle in/gaylemcdgayle 20
z
Gayle Laakmann McDowell
How
To
Approach
W
W
Y
D
A
W
hat
ould
ou
o
t
ork
gayle in/gaylemcdgayle 21
z
Gayle Laakmann McDowell
How
To
Approach
S
K
I
R
cope
eycomponents
dentify issues
epair
gayle in/gaylemcdgayle 22
z
Gayle Laakmann McDowell
How
To
Approach
① Scope the Problem
 Askquestions
 Make appropriateassumptions
② Define Key Components
 Can besomewhatnaïve
③ Identify Issues
 Bottlenecks,tradeoffs
④ Repair & Redesign
DiscussTop->Down
Gayle Laakmann McDowell 23gayle in/gaylemcdgayle
How to Act
DRIVE
 Leadtheprocess
 Be openaboutissues
TEAMWORK
 Beopentofeedback
 Tweak asnecessary
gayle in/gaylemcdgayle 24
z
Gayle Laakmann McDowell
How
To
Prepare
Read about design of major
companies
 Twitter,Facebook,Quora,Google,etc.
 ThinkaboutWHY they’redesigned
thatway
Learn/review key concepts
 Taskqueues,databases,sharding,etc.
Practice questions
Algorithm Preparation
Problem solving, not puzzles!
Gayle Laakmann McDowell 26gayle in/gaylemcdgayle
Why?
Strong CS
fundamentals
Analytical skills
Make tradeoffs
Push throughhard
problems
Communication
How you think
gayle in/gaylemcdgayleGayle Laakmann McDowell 27
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 28
Preparation
ImplementDS/Algorithms
MASTER BigO
Practice with interviewquestions
Code on paper/whiteboard
Mock interviews
PUSHYOURSELF!
Solving Algorithms
How to… attempt to solve a hard problem
gayle in/gaylemcdgayle 30
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 31
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 32
z
Gayle Laakmann McDowell
How
To
Approach
CrackingTheCodingInterview.com“Resources”
gayle in/gaylemcdgayle 33Gayle Laakmann McDowell
step
Listen (for clues)
Gayle Laakmann McDowell 34gayle in/gaylemcdgayle
What’sthe clue?
Anagram server
 Ex: rates ->aster, stare, taser, tears
Clue:why is it ona server?
gayle in/gaylemcdgayle 35Gayle Laakmann McDowell
step
Draw an Example
Big Enough
General Purpose
+
gayle in/gaylemcdgayleGayle Laakmann McDowell 36
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 37
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 38Gayle Laakmann McDowell
step
Brute Force / Naive
Stupid&terribleisokay!
gayle in/gaylemcdgayle 39Gayle Laakmann McDowell
step
Optimize
Walk through brute
force
Look for optimizations
Gayle Laakmann McDowell 40gayle 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 41gayle in/gaylemcdgayle
(A) Look for BUD
Bottlenecks
Unnecessary work
Duplicated work
Gayle Laakmann McDowell 42gayle 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 43gayle in/gaylemcdgayle
What’s unnecessary?
 Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000
 Unnecessary: looking for d
U
Gayle Laakmann McDowell 44gayle in/gaylemcdgayle
What’s unnecessary?
 Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000
 Unnecessary: looking for d
U
Gayle Laakmann McDowell 45gayle in/gaylemcdgayle
What’s duplicated?
 Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000
 Duplicated: c, d pairs
D
Gayle Laakmann McDowell 46gayle 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
… … …
Gayle Laakmann McDowell 47gayle 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)
… …
Gayle Laakmann McDowell 48gayle in/gaylemcdgayle
What’s duplicated?
 Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000
D
Gayle Laakmann McDowell 49gayle in/gaylemcdgayle
What’s duplicated?
 Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000
D
Gayle Laakmann McDowell 50gayle in/gaylemcdgayle
(B)Space/TimeTradeoffs
Hashtables & other datastructures
Precomputing
Gayle Laakmann McDowell 51gayle 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 52gayle 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 53gayle 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 54gayle in/gaylemcdgayle
(C)Do it yourself
Findpermutationsof swithinb
 s = abbc
 b = babcabbacaabcbabcacbb
Findthem!
 … now how didyou actuallydoit?
Gayle Laakmann McDowell 55gayle 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 56gayle 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
• Careful!“This sounds recursive” is 50%
accurate
• Bottom-up approach, top-down
implementation
Gayle Laakmann McDowell 57gayle in/gaylemcdgayle
(E) Solve “incorrectly”
① Develop incorrectsolution
② Identifywhy preciselyit’s incorrect
③ Repair
④ (& Repeat)
Gayle Laakmann McDowell 58gayle in/gaylemcdgayle
(E)Solve “incorrectly”
Random node in BST
Try: flipcoin
Coin=Heads
 Branch Left
Coin=Tails
 Branch Right
Gayle Laakmann McDowell 59gayle 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 60gayle in/gaylemcdgayle
(E)Solve “incorrectly”
Random node in BST
Try:
 Return rootwith1/n probability
 Then flipcoin(heads left,tails->right)
Gayle Laakmann McDowell 61gayle 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 62gayle in/gaylemcdgayle
(F) Other Data Structures
Giving outphone numbers
 “I wantany availablenumber”
 “I wantthisnumber”
Try: sorted array?Sorted linkedlist?Hashtable?
BST?
gayle in/gaylemcdgayle 63Gayle Laakmann McDowell
step
Walk Through
Know the variables
andwhen they change
gayle in/gaylemcdgayle 64Gayle Laakmann McDowell
step
Write Beautiful Code
Gayle Laakmann McDowell 65gayle in/gaylemcdgayle
How to Write WhiteboardCode
Write straight
Top-leftcorner
Use arrows if needed
Error cases / TODOs
Good variables
Modularized
Languagechoiceisuptoyou!
gayle in/gaylemcdgayleGayle Laakmann McDowell 66
Modularization
gayle in/gaylemcdgayle 67Gayle Laakmann McDowell
step
Testing
FIRST Analyze
 What’sitdoing?Why?
 Anythingthatlooksweird?
 Errorhotspots
THEN use test cases
 Smalltestcases
 Edgecases
 Bigger testcases
Final Thoughts
And questions
03
Gayle Laakmann McDowell 69gayle in/gaylemcdgayle
ClosingAdvice
Do projects
Study for your interviews
Chaseinterviews
… but don’t chase money
Check-inon your career.
 Isthiswhatyouwanttodowithyourlife?
McDowell | CareerCup.com
gayle in/gaylemcdgayle 70
z
Gayle Laakmann McDowell
It’s done
for a
reason!
Be a great teammate.
Be a great engineer.
gayle in/gaylemcdgayleGayle Laakmann McDowell 71
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

Cracking the Coding interview (College)

  • 1.
    GayleL. McDowell |Founder/ CEO gayle in/gaylemcdgayle Cracking the Coding Interview Harvard CareerCup.com
  • 2.
    gayle in/gaylemcdgayleGayle LaakmannMcDowell 2 Hi! I’m Gayle LaakmannMcDowell Author Interview Coach Interview Consulting <dev> </dev> (CS) (MBA)
  • 3.
    Gayle Laakmann McDowell3gayle in/gaylemcdgayle Yes! Slidesare online! Gayle.com  Click“Events”
  • 4.
  • 5.
    Gayle Laakmann McDowell5gayle in/gaylemcdgayle How to Get an Interview Your Background  Education  Work Experience  Projects  Github/ OnlineProfile Make a great resume McDowell | CareerCup.com
  • 6.
    Gayle Laakmann McDowell6gayle in/gaylemcdgayle Did I mention… PROJECTS???
  • 7.
    gayle in/gaylemcdgayle 7GayleLaakmann McDowell How We Review Resumes 1. Pull resume out of giant stack 2. Spot-check: companies, projects, etc. 3. Skim bullets to see if you’ve written real code. 4. Go tonextresume & whine abouthowmany moreyouhaveleft. InterviewReject “Glancedat,”not read. 15seconds
  • 8.
    How CS ResumeShouldLook Short (1– 2 line bullets) 3 – 4 Projects Courses & independent Finished or unfinished List of Technical Skills Short! Cut the “fluff.” GPA if at least 3.0 max (in-major, overall) One Page Only! Unless > 10 years exp. A Real Resume Format with organized columns Focus on Accomplishments not responsibilities Observe: No Objective! Objectives / summaries are almost always useless.
  • 9.
    gayle in/gaylemcdgayle 9GayleLaakmann McDowell Talking to Recruiters Show:  What you’vedone(mobileapp?Show it!)  What you’reexcitedabout Have a “pitch” ready Weird is okay  (arrogantisnot) McDowell | CareerCup.com
  • 10.
  • 11.
    gayle in/gaylemcdgayleGayle LaakmannMcDowell 11 The Pitch /Resume Walk-Through • Showsof success • Prompt the interviewer • Hobbies
  • 12.
    Gayle Laakmann McDowell12gayle in/gaylemcdgayle Your Past Work  1 – 2 Hard Projects  Hard/ cool  Youwerecentral  Technical depth  All Past Work  Challenges,architecture, tradeoffs,mistakes,successes, motivations  Whatdid YOU do?
  • 13.
    Technical Questions Why why whywhy why why meeeee 02
  • 14.
    gayle in/gaylemcdgayle 14GayleLaakmann McDowell How You’re Judged How did you do RELATIVE to other candidates on the SAME question? … it’s about how quickly you solved it relative to other candidates. It’s not about how quickly you solved the problem…
  • 15.
    gayle in/gaylemcdgayle 15 z GayleLaakmann McDowell What Really Happens
  • 16.
    gayle in/gaylemcdgayle 16 z GayleLaakmann McDowell What Really Happens Knowledge Questions  +Coding Design/Scalability  +Coding Algorithms/Problem Solving  +Coding
  • 17.
    Knowledge Questions How doindices work in SQL?
  • 18.
    Gayle Laakmann McDowell18gayle in/gaylemcdgayle Knowledge Questions If you list it, know it If you don’t know it, admit it  Deriveitifpossible.
  • 19.
    Design How would youdesign TinyURL?
  • 20.
    gayle in/gaylemcdgayle 20 z GayleLaakmann McDowell How To Approach W W Y D A W hat ould ou o t ork
  • 21.
    gayle in/gaylemcdgayle 21 z GayleLaakmann McDowell How To Approach S K I R cope eycomponents dentify issues epair
  • 22.
    gayle in/gaylemcdgayle 22 z GayleLaakmann McDowell How To Approach ① Scope the Problem  Askquestions  Make appropriateassumptions ② Define Key Components  Can besomewhatnaïve ③ Identify Issues  Bottlenecks,tradeoffs ④ Repair & Redesign DiscussTop->Down
  • 23.
    Gayle Laakmann McDowell23gayle in/gaylemcdgayle How to Act DRIVE  Leadtheprocess  Be openaboutissues TEAMWORK  Beopentofeedback  Tweak asnecessary
  • 24.
    gayle in/gaylemcdgayle 24 z GayleLaakmann McDowell How To Prepare Read about design of major companies  Twitter,Facebook,Quora,Google,etc.  ThinkaboutWHY they’redesigned thatway Learn/review key concepts  Taskqueues,databases,sharding,etc. Practice questions
  • 25.
  • 26.
    Gayle Laakmann McDowell26gayle in/gaylemcdgayle Why? Strong CS fundamentals Analytical skills Make tradeoffs Push throughhard problems Communication How you think
  • 27.
    gayle in/gaylemcdgayleGayle LaakmannMcDowell 27 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
  • 28.
    gayle in/gaylemcdgayleGayle LaakmannMcDowell 28 Preparation ImplementDS/Algorithms MASTER BigO Practice with interviewquestions Code on paper/whiteboard Mock interviews PUSHYOURSELF!
  • 29.
    Solving Algorithms How to…attempt to solve a hard problem
  • 30.
    gayle in/gaylemcdgayle 30 z GayleLaakmann McDowell What is NOT expected To know the answers To solve immediately To code perfectly (It’snice.Itjustdoesn’t happen*.) *Okayfine.Ithappenedonce,in2000+hiringpackets.
  • 31.
    gayle in/gaylemcdgayle 31 z GayleLaakmann McDowell What IS expected Be excitedabout hard problems More thanjust “correct” Drive! Keeptrying when stuck Write real code Showmehowyouthink!
  • 32.
    gayle in/gaylemcdgayle 32 z GayleLaakmann McDowell How To Approach CrackingTheCodingInterview.com“Resources”
  • 33.
    gayle in/gaylemcdgayle 33GayleLaakmann McDowell step Listen (for clues)
  • 34.
    Gayle Laakmann McDowell34gayle in/gaylemcdgayle What’sthe clue? Anagram server  Ex: rates ->aster, stare, taser, tears Clue:why is it ona server?
  • 35.
    gayle in/gaylemcdgayle 35GayleLaakmann McDowell step Draw an Example Big Enough General Purpose +
  • 36.
    gayle in/gaylemcdgayleGayle LaakmannMcDowell 36 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
  • 37.
    gayle in/gaylemcdgayleGayle LaakmannMcDowell 37 Ex:Intersection ofTwo Sorted Arrays Better: [1, 12, 15, 19, 20, 21] [2, 15, 17, 19, 21, 25, 27]  Big  No specialcases
  • 38.
    gayle in/gaylemcdgayle 38GayleLaakmann McDowell step Brute Force / Naive Stupid&terribleisokay!
  • 39.
    gayle in/gaylemcdgayle 39GayleLaakmann McDowell step Optimize Walk through brute force Look for optimizations
  • 40.
    Gayle Laakmann McDowell40gayle 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!
  • 41.
    Gayle Laakmann McDowell41gayle in/gaylemcdgayle (A) Look for BUD Bottlenecks Unnecessary work Duplicated work
  • 42.
    Gayle Laakmann McDowell42gayle 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
  • 43.
    Gayle Laakmann McDowell43gayle in/gaylemcdgayle What’s unnecessary?  Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000  Unnecessary: looking for d U
  • 44.
    Gayle Laakmann McDowell44gayle in/gaylemcdgayle What’s unnecessary?  Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000  Unnecessary: looking for d U
  • 45.
    Gayle Laakmann McDowell45gayle in/gaylemcdgayle What’s duplicated?  Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000  Duplicated: c, d pairs D
  • 46.
    Gayle Laakmann McDowell46gayle 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 … … …
  • 47.
    Gayle Laakmann McDowell47gayle 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) … …
  • 48.
    Gayle Laakmann McDowell48gayle in/gaylemcdgayle What’s duplicated?  Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000 D
  • 49.
    Gayle Laakmann McDowell49gayle in/gaylemcdgayle What’s duplicated?  Ex: a3 + b3 = c3 + d3 (1 <=a,b, c, d<= 1000 D
  • 50.
    Gayle Laakmann McDowell50gayle in/gaylemcdgayle (B)Space/TimeTradeoffs Hashtables & other datastructures Precomputing
  • 51.
    Gayle Laakmann McDowell51gayle 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
  • 52.
    Gayle Laakmann McDowell52gayle 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=
  • 53.
    Gayle Laakmann McDowell53gayle 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=
  • 54.
    Gayle Laakmann McDowell54gayle in/gaylemcdgayle (C)Do it yourself Findpermutationsof swithinb  s = abbc  b = babcabbacaabcbabcacbb Findthem!  … now how didyou actuallydoit?
  • 55.
    Gayle Laakmann McDowell55gayle 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!
  • 56.
    Gayle Laakmann McDowell56gayle 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 • Careful!“This sounds recursive” is 50% accurate • Bottom-up approach, top-down implementation
  • 57.
    Gayle Laakmann McDowell57gayle in/gaylemcdgayle (E) Solve “incorrectly” ① Develop incorrectsolution ② Identifywhy preciselyit’s incorrect ③ Repair ④ (& Repeat)
  • 58.
    Gayle Laakmann McDowell58gayle in/gaylemcdgayle (E)Solve “incorrectly” Random node in BST Try: flipcoin Coin=Heads  Branch Left Coin=Tails  Branch Right
  • 59.
    Gayle Laakmann McDowell59gayle 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
  • 60.
    Gayle Laakmann McDowell60gayle in/gaylemcdgayle (E)Solve “incorrectly” Random node in BST Try:  Return rootwith1/n probability  Then flipcoin(heads left,tails->right)
  • 61.
    Gayle Laakmann McDowell61gayle 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
  • 62.
    Gayle Laakmann McDowell62gayle in/gaylemcdgayle (F) Other Data Structures Giving outphone numbers  “I wantany availablenumber”  “I wantthisnumber” Try: sorted array?Sorted linkedlist?Hashtable? BST?
  • 63.
    gayle in/gaylemcdgayle 63GayleLaakmann McDowell step Walk Through Know the variables andwhen they change
  • 64.
    gayle in/gaylemcdgayle 64GayleLaakmann McDowell step Write Beautiful Code
  • 65.
    Gayle Laakmann McDowell65gayle in/gaylemcdgayle How to Write WhiteboardCode Write straight Top-leftcorner Use arrows if needed Error cases / TODOs Good variables Modularized Languagechoiceisuptoyou!
  • 66.
    gayle in/gaylemcdgayleGayle LaakmannMcDowell 66 Modularization
  • 67.
    gayle in/gaylemcdgayle 67GayleLaakmann McDowell step Testing FIRST Analyze  What’sitdoing?Why?  Anythingthatlooksweird?  Errorhotspots THEN use test cases  Smalltestcases  Edgecases  Bigger testcases
  • 68.
  • 69.
    Gayle Laakmann McDowell69gayle in/gaylemcdgayle ClosingAdvice Do projects Study for your interviews Chaseinterviews … but don’t chase money Check-inon your career.  Isthiswhatyouwanttodowithyourlife? McDowell | CareerCup.com
  • 70.
    gayle in/gaylemcdgayle 70 z GayleLaakmann McDowell It’s done for a reason! Be a great teammate. Be a great engineer.
  • 71.
    gayle in/gaylemcdgayleGayle LaakmannMcDowell 71 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