Cracking the Facebook Coding Interview I 3 Facebook








































![Ex: Intersection of Two Sorted Arrays Better: [1, 12, 15, 19, 20, 21] [2, Ex: Intersection of Two Sorted Arrays Better: [1, 12, 15, 19, 20, 21] [2,](https://slidetodoc.com/presentation_image/0153ce247db5bb7dc149b487226e6da6/image-41.jpg)




![What’s the bottleneck? Ex: counting the intersection [1, 12, 15, 19, 20, 21] [2, What’s the bottleneck? Ex: counting the intersection [1, 12, 15, 19, 20, 21] [2,](https://slidetodoc.com/presentation_image/0153ce247db5bb7dc149b487226e6da6/image-46.jpg)


























- Slides: 72

Cracking the Facebook Coding Interview I <3 Facebook! Gayle L. Mc. Dowell | Founder / CEO Career. Cup gayle in/gaylemcd

00 Why am I here?

Why would Facebook prep you? !? Be more comfortable Be more prepared be YOUR best Avoid common mistakes Gayle Laakmann Mc. Dowell Take out the mystery gayle in/gaylemcd 3

Hi! I’m Gayle Laakmann Mc. Dowell (CS) (MBA) <dev> </dev> Author Gayle Laakmann Mc. Dowell Interview Coach gayle in/gaylemcd Interview Consulting 4

Yes! Slides are online! Gayle. com Click “Events” Ctrl-F for “Facebook” m o c. yle a g @ g l: i a p e m r E p b f : t c Subje Gayle Laakmann Mc. Dowell gayle in/gaylemcd 5

m o c. e yl a g @ g : l i a p e m r E p b f : t c e Subj What to Expect

A Typical** Process (**not universal! Ask your recruiter) Hiring Committee & Decision Phone Onsite Algo / Coding ½ Behavioral ½ Algo / Coding Design Algo / Coding Gayle Laakmann Mc. Dowell gayle in/gaylemcd 7

5 Minutes Prior Experience Typical 45 Minutes Techz Question #1 Question #2 Interview 5 Minutes Questions FOR Interviewer Gayle Laakmann Mc. Dowell gayle in/gaylemcd 8

Email: [email protected] com Subject: fbprep 02 Behavioral Questions The soft squishy stuff.

The Pitch / Resume Walk-Through • Shows of success • Prompt the interviewer • Hobbies Gayle Laakmann Mc. Dowell gayle in/gaylemcd 10

Your Past Work 1 – 2 Hard Projects n n n All Past Work Hard / cool You were central Technical depth n n What did YOU do? Challenges, architecture, tradeoffs, mistakes, successes, motivations Teamwork, leadership, conflicts, etc What would you do differently? Gayle Laakmann Mc. Dowell gayle in/gaylemcd 11

Be PASSIONATE What about z YOU? Be KNOWLEDGEABLE Be a GOOD TEAMMATE Gayle Laakmann Mc. Dowell gayle in/gaylemcd 12

m o c. e l y a g @ Email: g p e r p b f : t c e j S ub 03 Design Questions Big, meaty problems

What Would You Do At Work How To z Approach Gayle Laakmann Mc. Dowell gayle in/gaylemcd 14

Scope Key components Identify issues Repair How To z Approach Gayle Laakmann Mc. Dowell gayle in/gaylemcd 15

① Scope the Problem Ask questions Make appropriate assumptions n n How To ② Define Key Components z Can be somewhat naïve n Approach ③ Identify Issues Bottlenecks, tradeoffs n ④ Repair & Redesign Discuss Top-> Down Gayle Laakmann Mc. Dowell gayle in/gaylemcd 16

How to Act DRIVE n n TEAMWORK Lead the process Be open about issues n n Be open to feedback Tweak as necessary Use the whiteboard! Gayle Laakmann Mc. Dowell gayle in/gaylemcd 17

Read about design of major companies n How To Know key concepts n z n Tasks, sharding, caches. Web stack, REST, etc Practice back-of-theenvelope calculations Prepare Gayle Laakmann Mc. Dowell THINK, don’t memorize! gayle in/gaylemcd 18

Ema il: g @ga Subj ect: f yle. c bpre om p 04 Algorithm Questions Things that make you think

Why? Analytical skills How you think Make tradeoffs Gayle Laakmann Mc. Dowell gayle Push through hard problems Communication Strong CS fundamentals gayle in/gaylemcd 20

Essential Knowledge Data Structures Algorithms Concepts Array. Lists Merge Sort Big O Time Hash Tables Quick Sort Big O Space Trees (+ Tries) Breadth-First Search Recursion Graphs Depth-First Search Memoization / Dynamic Programming Stacks / Queues Binary Search Heaps Gayle Laakmann Mc. Dowell gayle in/gaylemcd 21

Preparation MASTER Big O Implement DS/Algorithms Practice with interview questions Code on paper/whiteboard Mock interviews PUSH YOURSELF! Gayle Laakmann Mc. Dowell gayle in/gaylemcd 22

m o c. e yl a g @ g l: i a p e m r E p b f : t c Subje A Crash Course in Big O Just getting your feet wet

Basic for loop Print 0 through N Runtime? n Gayle Laakmann Mc. Dowell O(N) gayle in/gaylemcd 24

Nested loops Print pairs Runtime? n Gayle Laakmann Mc. Dowell O(N 2) gayle in/gaylemcd 25

More loops Print evens Runtime? n Gayle Laakmann Mc. Dowell O(N) gayle in/gaylemcd 26

Two loops Print evens, then odds Runtime? n Gayle Laakmann Mc. Dowell O(N) gayle in/gaylemcd 27

Basic for loop Print ordered pairs Runtime? O(N 2) x i: 0 N n j: 0 N x x x x x Gayle Laakmann Mc. Dowell gayle in/gaylemcd 28

Basic for loop Print ordered pairs Runtime? n Gayle Laakmann Mc. Dowell O(A * B) gayle in/gaylemcd 29

Okay now things are getting tougher! Step 1: O(P) n P = number of people Step 2: O(P * L) n L = max life span Step 3: O(Y) n Y = total # years O(P + P * L + Y) O(P * L + Y) Gayle Laakmann Mc. Dowell gayle in/gaylemcd 30

Eeek. Recursion? Fibonacci Runtime? • Height of K • Each level doubles # nodes • O(2 k) *** Actually slightly less for complex math reasons. Gayle Laakmann Mc. Dowell gayle in/gaylemcd 31

Eeek. Recursion? Fibonacci, part 2 Runtime? • Height of K • Each level has ONE node • O(k) Gayle Laakmann Mc. Dowell gayle in/gaylemcd 32

m o c. e yl a g @ g l: i a p e m r E p b f : t c Subje Solving Algorithms How to… attempt to solve a hard problem

To know the answers To solve immediately To code perfectly What is NOT z (It’s nice. It just doesn’t happen*. ) expected * Okay fine. It happened once, in 2000+ hiring packets. Gayle Laakmann Mc. Dowell gayle in/gaylemcd 34

Be excited about hard problems Drive! What IS z n Keep trying when stuck n More than just “correct” Pay attention to me! Write real code expected Show me how you think! Gayle Laakmann Mc. Dowell gayle in/gaylemcd 35

Cracking. The. Coding. Interview. com “Resources” How To z Approach m co. e l y a g @ g : l i Ema t: fbprep c e j b u S Gayle Laakmann Mc. Dowell gayle in/gaylemcd 36

Listen (for clues) step 1 Gayle Laakmann Mc. Dowell gayle in/gaylemcd 37

What’s the clue? Anagram server n Ex: rates -> aster, stare, taser, tears Clue: why is it on a server? Gayle Laakmann Mc. Dowell gayle in/gaylemcd 38

Draw an Example Big Enough step 2 Gayle Laakmann Mc. Dowell + General Purpose gayle in/gaylemcd 39

Ex: Intersection of Two Sorted Arrays Most people draw something like this: [1, 12, 15, 19] [2, 13, 20] n n Too small Too special-case-y • same size, one common element, same index Gayle Laakmann Mc. Dowell gayle in/gaylemcd 40
![Ex Intersection of Two Sorted Arrays Better 1 12 15 19 20 21 2 Ex: Intersection of Two Sorted Arrays Better: [1, 12, 15, 19, 20, 21] [2,](https://slidetodoc.com/presentation_image/0153ce247db5bb7dc149b487226e6da6/image-41.jpg)
Ex: Intersection of Two Sorted Arrays Better: [1, 12, 15, 19, 20, 21] [2, 15, 17, 19, 21, 25, 27] n n Gayle Laakmann Mc. Dowell Big No special cases gayle in/gaylemcd 41

Brute Force / Naive step 3 Stupid & terrible is okay! Gayle Laakmann Mc. Dowell gayle in/gaylemcd 42

Optimize step 4 Gayle Laakmann Mc. Dowell Walk through brute force Look for optimizations gayle in/gaylemcd 43

Techniques to Develop Algorithms BUD Space and Time Do It Yourself Recursion Gayle Laakmann Mc. Dowell gayle o y h s u P gayle in/gaylemcd ! f l e s r u 44

(A) Look for BUD Bottlenecks Unnecessary work Duplicated work Gayle Laakmann Mc. Dowell gayle in/gaylemcd 45
![Whats the bottleneck Ex counting the intersection 1 12 15 19 20 21 2 What’s the bottleneck? Ex: counting the intersection [1, 12, 15, 19, 20, 21] [2,](https://slidetodoc.com/presentation_image/0153ce247db5bb7dc149b487226e6da6/image-46.jpg)
What’s the bottleneck? Ex: counting the intersection [1, 12, 15, 19, 20, 21] [2, 15, 17, 19, 21, 25, 27] Bottleneck: searching B Gayle Laakmann Mc. Dowell gayle in/gaylemcd 46

What’s unnecessary? Ex: a 3 + b 3 = c 3 + d 3 (1 <= a, b, c, d <= 1000 Unnecessary: looking for d U Gayle Laakmann Mc. Dowell gayle in/gaylemcd 47

What’s unnecessary? Ex: a 3 + b 3 = c 3 + d 3 (1 <= a, b, c, d <= 1000 Unnecessary: looking for d U Gayle Laakmann Mc. Dowell gayle in/gaylemcd 48

What’s duplicated? Ex: a 3 + b 3 = c 3 + d 3 (1 <= a, b, c, d <= 1000 Duplicated: c, d pairs Gayle Laakmann Mc. Dowell gayle D in/gaylemcd 49

What’s duplicated? Ex: a 3 + b 3 = c 3 + d 3 Duplicated: c, d pairs Gayle Laakmann Mc. Dowell gayle (1 <= a, b, c, d <= 1000 c d c 3 + d 3 … … … 4 31 29855 4 32 32832 4 33 36001 … … … 5 59 205504 5 60 216125 5 61 227106 … … … in/gaylemcd D 50

What’s duplicated? Ex: a 3 + b 3 = c 3 + d 3 (1 <= a, b, c, d <= 1000 c 3 + d 3 (c, d) … … 29855 (4, 31) 32832 (4, 32), (18, 30) 36001 (4, 33) … … 205504 Duplicated: c, d pairs 216125 (5, 59) 227106 (5, 61) … … Gayle Laakmann Mc. Dowell gayle (5, 60), (45, 50) in/gaylemcd D 51

What’s duplicated? Ex: a 3 + b 3 = c 3 + d 3 (1 <= a, b, c, d <= 1000 D Gayle Laakmann Mc. Dowell gayle in/gaylemcd 52

What’s duplicated? Ex: a 3 + b 3 = c 3 + d 3 (1 <= a, b, c, d <= 1000 D Gayle Laakmann Mc. Dowell gayle in/gaylemcd 53

(B) Space/Time Tradeoffs Hash tables & other data structures Precomputing Gayle Laakmann Mc. Dowell gayle in/gaylemcd 54

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 rectangles and sums Gayle Laakmann Mc. Dowell gayle in/gaylemcd 55

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 = Gayle Laakmann Mc. Dowell - + gayle + 10 in/gaylemcd 56

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 = Gayle Laakmann Mc. Dowell - + gayle + 13 in/gaylemcd 57

(C) Do it yourself Find permutations of s within b s = abbc n b = babcabbacaabcbabcacbb n Find them! n Gayle Laakmann Mc. Dowell … now how did you actually do it? gayle in/gaylemcd 58

(D) Recursion / Base Case & Build Subsets of a set n n {} {a} {}, {a} {a, b} {}, {a}, {b}, {a, b} {a, b, c} … Subsets of {S 1…Sn-1} + Sn to each Gayle Laakmann Mc. Dowell gayle • Careful! “This sounds recursive” is 50% accurate • Bottom-up approach, topdown implementation • “Backtracking” Recursion • Draw a “call tree”. Look for repeated subproblems. in/gaylemcd 59

Techniques to Develop Algorithms BUD Space and Time Do It Yourself Recursion Gayle Laakmann Mc. Dowell gayle o y h s u P gayle in/gaylemcd ! f l e s r u 60

Walk Through step 5 Gayle Laakmann Mc. Dowell Know the variables and when they change gayle in/gaylemcd 61

Write Beautiful Code step 6 Gayle Laakmann Mc. Dowell gayle in/gaylemcd 62

How to Write Whiteboard Code Write straight Top-left corner Use arrows if needed Error cases / TODOs Good variables Modularized Language choice is up to you! Gayle Laakmann Mc. Dowell gayle in/gaylemcd 63

Modularization Gayle Laakmann Mc. Dowell gayle in/gaylemcd 64

Testing FIRST Analyze step n 7 n n THEN use test cases n n n Small test cases Edge cases Bigger test cases BUT… n n Gayle Laakmann Mc. Dowell What’s it doing? Why? Anything that looks weird? Error hot spots gayle Test code, not algorithm Think before you fix gayle in/gaylemcd 65

m o c. e yl a g @ g : l Emai t: fbprep c e j b Su 05 Questions for Your Interviewer What do you want to know?

Be Prepared With Questions Passion Knowledge Interest Communication Curiosity Gayle Laakmann Mc. Dowell gayle in/gaylemcd 67

Consider… What’s made you happy / unhappy? What are your goals? Gayle Laakmann Mc. Dowell gayle Culture & work style Career goals Technology gayle in/gaylemcd 68

Ema il: Sub ject: [email protected] le. c fbpr om ep 06 Final Thoughts And questions

Be a great teammate. It’s done for az reason! Gayle Laakmann Mc. Dowell Be a great engineer. gayle in/gaylemcd 70

But wait, there’s one more thing. . . m o c. e yl a g @ g : l i a p e m r E p b f : t c e Subj SURVEY: Coming your way. READY? Follow up with your recruiter to schedule your next steps. JOB POSTINGS: facebook. com/careers/teams/engineering SLIDES? Gayle. com -> Events -> search “Facebook” Gayle Laakmann Mc. Dowell gayle in/gaylemcd 71

Other Resources Gayle. com Career. Cup. com Cracking. The Coding. Interview. com Or, follow me online • • • m o c. e l y a g Email: [email protected] ep r p b f : t c e j b Su Gayle Laakmann Mc. Dowell gayle in/gaylemcd facebook. com/gayle twitter. com/gayle. com [email protected] com quora. com 72
Cracking the Coding Interview o Its a book
Cracking the Coding Interview Diego Aguirre Problem Solving
Interview Tips Chaz Palisoc Agenda Interview Tips Interview
Interview Techniques INTERVIEW l Definition for interview l
Interview Techniques INTERVIEW l Definition for interview l
Exploit Password Cracking An Overview on Password Cracking
4 Thermal cracking steam cracking Since 1912 thermal
Cracking Say why we need cracking and the
Organic Chemistry 1 Crude oil and cracking Cracking
Coding in noisy channel Source coding Channel coding
Beginning Coding CodeaPillars and Beebots Why Coding Coding
Coding Coding n What is coding In qualitative
Coding 101 Taken from Beginning Coding Intermediate Coding
Facebook Applications Teppo Risnen Facebook Applications Facebook provides
Propagcia Facebook Facebook tatistiky q Na Facebook je
Facebook Facebook O Facebook es un sitio web
Facebook Applications Teppo Risnen Facebook Applications Facebook provides
COGNITIVE INTERVIEW TECHNIQUE Compliments the Interview by verifying
Have a Job Interview The IKEA Job Interview
Interview Typy rozhovor strukturovan semistrukturovan nestrukturovan vod interview
Interview Skills Workshop Objectives l Typical Interview Structure
Interview Exercise Past vs Present Interview a classmate
From Interview to Offer Key Job Interview Tactics
Interview 1 Definisi Interview wawancara adalah proses komunikasi
interview SCID Structured Clinical Interview for DSM5 SCID5
Informational Interview Thomas PW Informational Interview Tujuan memperoleh
Interview Skills Effectively handling common interview questions Wei
THE INTERVIEW PREPARE PRACTICE Parts of an interview
Interview projects How did your followup interview go
CLINICAL INTERVIEW Gemah Nuripah Two interview style l
Culturele Interview Wat is het culturele interview 4
COOPERATIVE LEARNING ThreeSteps Interview ThreeSteps Interview Threestep interviews
CV Interview Preparation CV Interview Preparation The purpose
JOB INTERVIEW PREPARE FOR YOUR INTERVIEW CALLING YOUR
Interview Etiquette Before the Interview Set reminders for
INTERVIEW PREPARATION Before The Interview Research the potential
Interview Tips Chaz Palisoc Agenda Interview Tips Effective
Interviewing Candidates Interview An interview is a procedure
The Job Interview a Web Quest The Interview
COOPERATIVE LEARNING ThreeSteps Interview ThreeSteps Interview Threestep interviews
The Informational Interview What Interview designed to produce
WAWANCARA INTERVIEW BAIHAQI HERMANSYAH Pengertian Wawancara Interview l
PENGANTAR WAWANCARA The Interview Defined An interview is
Nailing the PreTest Interview Interview The key to
INTERVIEW TIPS AND TABOOS WHY INTERVIEW They seem