3. gayle in/gaylemcdgayleGayle Laakmann McDowell 3
Why wouldFacebookprepyou?!?
Be more
comfortable
Be more prepared
Take out
the mystery
Avoid common
mistakes
12. Gayle Laakmann McDowell 12gayle in/gaylemcdgayle
Your Past Work
3+ Projects
Hard / cool
You werecentral
Technical depth
All Past Work
TECHNICAL:Challenges,
architecture, tradeoffs,
successes, motivations
SOFT:Teamwork, leadership,
conflicts, etc
What did YOU do?
What would you do differently?
17. gayle in/gaylemcdgayle 17
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
Breadth-first,notdepth-first
30. gayle in/gaylemcdgayleGayle Laakmann McDowell 30
Basicfor loop
Printordered pairs
Runtime?
O(N2)
j : 0 N
i:0N
x x x x x x
x x x x x
x x x x
x x x
x x
x
32. gayle in/gaylemcdgayleGayle Laakmann McDowell 32
Okay now thingsare getting tougher!
Step 1: O(P)
P = numberof people
Step 2: O(P * Y)
Y = max life span
Step 3: O(L)
L = last death year
O(P + P * Y + L) O(P * Y + L)
35. gayle in/gaylemcdgayleGayle Laakmann McDowell 35
Fibonacci
Eeek. Recursion?
• Height of N
• Each level doubles # nodes
• O(2N) time ***
• O(N) space
Actuallyslightlylessforcomplexmathreasons.
36. gayle in/gaylemcdgayleGayle Laakmann McDowell 36
Fibonacci, part 2
Runtime?
Eeek. Recursion?
• Height of N
• Each level has <=2nodes
• O(N) time
• O(N) space
37. gayle in/gaylemcdgayleGayle Laakmann McDowell 37
Reminders
Drop constants
Don’t drop non-constants
Differentvariables
Avoid ‘n’
Add vs. Multiply
Recursion call tree
39. gayle in/gaylemcdgayle 39
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.
40. gayle in/gaylemcdgayle 40
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!
43. Gayle Laakmann McDowell 43gayle in/gaylemcdgayle
What’s the clue?
Anagram server
Ex: rates ->aster, stare, taser, tears
Clue:why is it on a server?
Key(sorted string) Value (list of words)
aerst rates, aster, stare, taser, tears,
dgo dog, god
acll call
… …
44. gayle in/gaylemcdgayle 44Gayle Laakmann McDowell
step
Draw an Example
INTERSECTION SIZE: Find #
elementsin common between
two sorted, distinct arrays:
45. gayle in/gaylemcdgayleGayle Laakmann McDowell 45
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
62. gayle in/gaylemcdgayleGayle Laakmann McDowell 62
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
63. Gayle Laakmann McDowell 63gayle 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
64. Gayle Laakmann McDowell 64gayle in/gaylemcdgayle
(D)Recursion
Use, but don’t cling to, recursion
“instinct”
Trybottom-up
“Backtracking”
Draw call-tree
Derive runtime
Find repeated subproblems
Subsets of a set
{} {}
{a}{},{a}
{a,b} {},{a},{b},{a,b}
{a,b, c} …
Subsets of {S1…Sn-1} +Sn to each
65. Gayle Laakmann McDowell 65gayle in/gaylemcdgayle
Techniquesto Develop Algorithms
BUD
Space and Time
Do It Yourself
Recursion
74. gayle in/gaylemcdgayle 74Gayle 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
Find permutationsof s withinb:
s = abbc
b = babcabbacaabcbabcacbb
for (i = 0; i < b.len – s.len; i++) {
if (isPerm(s, b.subs(i, s.len)) …
}
77. Gayle Laakmann McDowell 77gayle in/gaylemcdgayle
Prepare some questions
What’s made you
happy / unhappy?
What are your goals?
Culture& work style
Career paths
Technology
Interviewer’s
experience