SlideShare una empresa de Scribd logo
1 de 37
Descargar para leer sin conexión
Surviving & Thriving in
Technical Interviews
Making your brain do
hard things while
under pressure
Surviving & Thriving in
Technical Interviews
Making your brain do
hard things while
under pressure
Why is it
so hard?!
What Are Interviewers Looking For?
ü  Ability to solve problems
ü  Technical skills
ü  Soft Skills
ü  Team Fit
§  Understand the problem
§  Think logically
§  Explain Yourself
§  Propose a solution
§  Analyze solution
§  Make improvements
§  Handle changes or constraints
Ability to Solve Problems
§  Domain-specific Knowledge
§  Data Structures
§  Algorithms
§  Design Patterns
§  Dealing with Large Data Sets
Technical Skills
§  Array
§  Hash Map
§  Linked List
§  Stack
§  Queue
§  Tree
§  Heap
§  Graph
§  Searching
§  Linear Search
§  Binary Search
§  Sorting
§  Selection Sort
§  Insertion Sort
§  Merge Sort
§  Quicksort
§  Bucket Sort
Data Structures & Algorithms
§  Used to classify algorithms by their time
complexity – how their processing time
is affected by input size.
§  Basic Classifications:
Big-O Notation & Time Complexity
§ Constant – O(1) or O(c)	
  
§ Logarithmic – O(log	
  n)	
  
§ Linear – O(n)	
  
§ Linearithmic – O(n	
  log	
  n)	
  
§ Quadratic – O(n2)	
  
§ Polynomial – O(nc)	
  
§ Exponential – O(cn)	
  
§ Factorial – O(n!)	
  
§  The amount of memory cells an
algorithm needs.
§  Often have to evaluate
tradeoffs between
space and time
complexity
§  Doing things "in-place" or not
Space Complexity
§  Communication
§  Teamwork
§  Leadership
§  Confidence
§  Responsibility
See Amazon Leadership Principles - http://amzn.to/Qb6JB6
Soft Skills
Technical Interview
Question Examples
I don't mind doing interviews. I don't
mind answering thoughtful
questions. But I'm not thrilled about
answering questions like, 'If you
were being mugged, and you had a
light saber in one pocket and a whip
in the other, which would you use?'
– Harrison Ford
“
”
Example #1 – The Raffle
§  Tickets are numbered from 1 to 1,000,000
§  Select 700,000 random winners
§  No duplicates
The Raffle – Solution #1
$winners	
  =	
  array_rand(	
  
	
  array_fill_keys(range(1,	
  1000000),	
  true),	
  
	
  700000	
  
);	
  
The Raffle – Solution #1
PROS
§  Succinct
§  Uses native functions
§  Pretty fast
§  O(n)	
  
$winners	
  =	
  array_rand(array_fill_keys(range(1,	
  1000000),	
  true),	
  700000);	
  
The Raffle – Solution #1
PROS
§  Succinct
§  Uses native functions
§  Pretty fast
§  O(n)	
  
CONS
§  Memory hog!
§  Crashes on higher
numbers
§  Not very random due
to how array_rand()
works
$winners	
  =	
  array_rand(array_fill_keys(range(1,	
  1000000),	
  true),	
  700000);	
  
The Raffle – Solution #2
$winners	
  =	
  array();	
  
for	
  ($i	
  =	
  1;	
  $i	
  <=	
  700000;	
  $i++)	
  {	
  
	
  	
  	
  $n	
  =	
  mt_rand(1,	
  1000000);	
  
	
  	
  	
  if	
  (isset($winners[$n]))	
  {	
  
	
  	
  	
  	
  	
  	
  $i-­‐-­‐;	
  
	
  	
  	
  }	
  else	
  {	
  
	
  	
  	
  	
  	
  	
  $winners[$n]	
  =	
  true;	
  
	
  	
  	
  }	
  
}	
  
$winners	
  =	
  array_keys($winners);	
  
	
  
Note:The "mt" in
mt_rand()	
  stands for
Mersenne Twister.
The Raffle – Solution #2
$winners	
  =	
  array();	
  
for	
  ($i	
  =	
  1;	
  $i	
  <=	
  700000;	
  $i++)	
  
{	
  
	
  	
  	
  	
  $n	
  =	
  mt_rand(1,	
  1000000);	
  
	
  	
  	
  	
  if	
  (isset($winners[$n]))	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  $i-­‐-­‐;	
  
	
  	
  	
  	
  }	
  else	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  $winners[$n]	
  =	
  true;	
  
	
  	
  	
  	
  }	
  
}	
  
$winners	
  =	
  array_keys($winners);	
  
PROS
§  Lower memory than #1
§  Very good randomness
CONS
§  Not really O(n)
§  ~10x slower than #1
§  Extra step to get results
The Raffle – Solution #3
$winners	
  =	
  range(1,	
  1000000);	
  
shuffle($winners);	
  
$winners	
  =	
  array_slice($winners,	
  0,	
  700000);	
  
	
  
PROS
§  Fast
§  O(n)
§  Lower memory
than #1
CONS
§  More random than #1,
but not as random as #2
CONS
§  More random than #1,
but not as random as #2
PROS
§  Fast
§  O(n)
§  Low memory
The Raffle – Solution #3
$winners	
  =	
  range(1,	
  1000000);	
  
shuffle($winners);	
  
$winners	
  =	
  array_slice($winners,	
  0,	
  700000);	
  
	
  
How To Improve: Use a Fisher-Yates shuffle
algorithm that is seeded with mt_rand().This
would increase the randomness without
negatively affecting performance.
The Raffle – Follow Up
What if there were
1,000,000,000 tickets?
The Raffle – Follow Up
What if there were
1,000,000,000 tickets?
php	
  >	
  $r	
  =	
  range(1,	
  1000000000);	
  
PHP	
  Fatal	
  error:	
  	
  Allowed	
  memory	
  size	
  of	
  536870912	
  bytes	
  exhausted	
  
Example #2 – Odd Duck
§  Input: an array of non-negative integers
§  Integers in the array all exist
an even number of times
§  Except for one of them…
Find the "odd duck"
Odd Duck – Before You Start
§  It's OK to ask clarifying questions
§  What kind of questions would you ask?
Odd Duck – Before You Start
§  It's OK to ask clarifying questions
§  What kind of questions would you ask?
§  Is an empty array valid? No.
§  Is a single-element array valid? Yes.
§  Is the array sorted? No.
§  Can there be more than one instance of the
"odd duck"? Yes.
Odd Duck – Before You Start
§  It's OK to ask clarifying questions
§  What kind of questions would you ask?
§  Is an empty array valid? No.
§  Is a single-element array valid? Yes.
§  Is the array sorted? No.
§  Can there be more than one instance of the
"odd duck"? Yes.
…	
  8	
  5	
  42	
  8	
  8	
  9	
  1	
  
42	
  1	
  1	
  8	
  9	
  5	
  …	
  
Odd Duck – Exercise
Odd Duck – Solutions
1.  For each number in the array, count the occurrences of
that number and check if it's odd. Bad choice: O(n2)
Odd Duck – Solutions
1.  For each number in the array, count the occurrences of
that number and check if it's odd. Bad choice: O(n2)	
  
2.  Use a 2nd array to count the occurrences of each
number, then look in that 2nd array for the odd one.
Odd Duck – Solutions
1.  For each number in the array, count the occurrences of
that number and check if it's odd. Bad choice: O(n2)	
  
2.  Use a 2nd array to count the occurrences of each
number, then look in that 2nd array for the odd one.
3.  Sort the array, and then look for the first occurrence of
a number that exists an odd number of times. (Bonus
points: look in pairs)
Odd Duck – Solutions
1.  For each number in the array, count the occurrences of
that number and check if it's odd. Bad choice: O(n2)	
  
2.  Use a 2nd array to count the occurrences of each
number, then look in that 2nd array for the odd one.
3.  Sort the array, and then look for the first occurrence of
a number that exists an odd number of times. (Bonus
points: look in pairs)
4.  Use a 2nd array.When you encounter a number, add it
to the 2nd array (as the key).When you encounter it
again, remove/unset it.
Odd Duck – Solutions
1.  For each number in the array, count the occurrences of
that number and check if it's odd. Bad choice: O(n2)	
  
2.  Use a 2nd array to count the occurrences of each
number, then look in that 2nd array for the odd one.
3.  Sort the array, and then look for the first occurrence of
a number that exists an odd number of times. (Bonus
points: look in pairs)
4.  Use a 2nd array.When you encounter a number, add it
to the 2nd array (as the key).When you encounter it
again, remove/unset it.
5.  XOR all of the array elements together. (Oh…)
Preparation and Tips
Preparing for the Questions
§  Research your potential employer
§  Be familiar with your own résumé
§  Review the job description
§  Practice technical interview questions
§  Review data structures and algorithms
§  Be prepared for behavioral questions
Behavioral Questions
§  Questions related to past experiences
§  "Give me an example of a time when…"
§  "Tell me about something you did that…"
§  "How do you handle a situation where…"
§  Plan some good experiences to share
§  Talk about "I", not "we", and be honest
§  Be prepared to give details
Physical Preparations
§  Be well-rested
§  Arrive early
§  Use the restroom before the interview
§  Turn off your phone
§  Assume business casual dress unless you
are told otherwise
Interview Tips
§  Don't Panic
§  Ask Questions
§  Don't Be Evasive
§  ShowYour Skills
§  Be Positive
§  Learn Something
Any Questions?
Presentation by
Jeremy Lindblom
@jeremeamia
Thanks!

Más contenido relacionado

Similar a Surviving Technical Interviews with Data Structures & Algorithms

Multimodal or Expensive Optimization
Multimodal or Expensive OptimizationMultimodal or Expensive Optimization
Multimodal or Expensive OptimizationOlivier Teytaud
 
(Radhika) presentation on chapter 2 ai
(Radhika) presentation on chapter 2 ai(Radhika) presentation on chapter 2 ai
(Radhika) presentation on chapter 2 aiRadhika Srinivasan
 
44 randomized-algorithms
44 randomized-algorithms44 randomized-algorithms
44 randomized-algorithmsAjitSaraf1
 
Random Forest and KNN is fun
Random Forest and KNN is funRandom Forest and KNN is fun
Random Forest and KNN is funZhen Li
 
Theories of continuous optimization
Theories of continuous optimizationTheories of continuous optimization
Theories of continuous optimizationOlivier Teytaud
 
It's Not Magic - Explaining classification algorithms
It's Not Magic - Explaining classification algorithmsIt's Not Magic - Explaining classification algorithms
It's Not Magic - Explaining classification algorithmsBrian Lange
 
Code Fast, die() Early, Throw Structured Exceptions
Code Fast, die() Early, Throw Structured ExceptionsCode Fast, die() Early, Throw Structured Exceptions
Code Fast, die() Early, Throw Structured ExceptionsJohn Anderson
 
Sienna 5 decreaseandconquer
Sienna 5 decreaseandconquerSienna 5 decreaseandconquer
Sienna 5 decreaseandconquerchidabdu
 
Memorization of Various Calculator shortcuts
Memorization of Various Calculator shortcutsMemorization of Various Calculator shortcuts
Memorization of Various Calculator shortcutsPrincessNorberte
 
Bias correction, and other uncertainty management techniques
Bias correction, and other uncertainty management techniquesBias correction, and other uncertainty management techniques
Bias correction, and other uncertainty management techniquesOlivier Teytaud
 
Uncertainties in large scale power systems
Uncertainties in large scale power systemsUncertainties in large scale power systems
Uncertainties in large scale power systemsOlivier Teytaud
 
Code Fast, Die Young, Throw Structured Exceptions
Code Fast, Die Young, Throw Structured ExceptionsCode Fast, Die Young, Throw Structured Exceptions
Code Fast, Die Young, Throw Structured ExceptionsJohn Anderson
 
The lengths of pregnancies are normally distributed with mean µ = .docx
The lengths of pregnancies are normally distributed with mean µ = .docxThe lengths of pregnancies are normally distributed with mean µ = .docx
The lengths of pregnancies are normally distributed with mean µ = .docxoreo10
 
Machine Learning on Azure - AzureConf
Machine Learning on Azure - AzureConfMachine Learning on Azure - AzureConf
Machine Learning on Azure - AzureConfSeth Juarez
 

Similar a Surviving Technical Interviews with Data Structures & Algorithms (20)

Multimodal or Expensive Optimization
Multimodal or Expensive OptimizationMultimodal or Expensive Optimization
Multimodal or Expensive Optimization
 
Chapter 4 ds
Chapter 4 dsChapter 4 ds
Chapter 4 ds
 
(Radhika) presentation on chapter 2 ai
(Radhika) presentation on chapter 2 ai(Radhika) presentation on chapter 2 ai
(Radhika) presentation on chapter 2 ai
 
GuessWhat?!
GuessWhat?!GuessWhat?!
GuessWhat?!
 
44 randomized-algorithms
44 randomized-algorithms44 randomized-algorithms
44 randomized-algorithms
 
Random Forest and KNN is fun
Random Forest and KNN is funRandom Forest and KNN is fun
Random Forest and KNN is fun
 
Combinations
CombinationsCombinations
Combinations
 
Theories of continuous optimization
Theories of continuous optimizationTheories of continuous optimization
Theories of continuous optimization
 
It's Not Magic - Explaining classification algorithms
It's Not Magic - Explaining classification algorithmsIt's Not Magic - Explaining classification algorithms
It's Not Magic - Explaining classification algorithms
 
Code Fast, die() Early, Throw Structured Exceptions
Code Fast, die() Early, Throw Structured ExceptionsCode Fast, die() Early, Throw Structured Exceptions
Code Fast, die() Early, Throw Structured Exceptions
 
Sienna 5 decreaseandconquer
Sienna 5 decreaseandconquerSienna 5 decreaseandconquer
Sienna 5 decreaseandconquer
 
Cis435 week06
Cis435 week06Cis435 week06
Cis435 week06
 
Algorithms Exam Help
Algorithms Exam HelpAlgorithms Exam Help
Algorithms Exam Help
 
Memorization of Various Calculator shortcuts
Memorization of Various Calculator shortcutsMemorization of Various Calculator shortcuts
Memorization of Various Calculator shortcuts
 
Bias correction, and other uncertainty management techniques
Bias correction, and other uncertainty management techniquesBias correction, and other uncertainty management techniques
Bias correction, and other uncertainty management techniques
 
Uncertainties in large scale power systems
Uncertainties in large scale power systemsUncertainties in large scale power systems
Uncertainties in large scale power systems
 
Code Fast, Die Young, Throw Structured Exceptions
Code Fast, Die Young, Throw Structured ExceptionsCode Fast, Die Young, Throw Structured Exceptions
Code Fast, Die Young, Throw Structured Exceptions
 
The lengths of pregnancies are normally distributed with mean µ = .docx
The lengths of pregnancies are normally distributed with mean µ = .docxThe lengths of pregnancies are normally distributed with mean µ = .docx
The lengths of pregnancies are normally distributed with mean µ = .docx
 
Machine Learning on Azure - AzureConf
Machine Learning on Azure - AzureConfMachine Learning on Azure - AzureConf
Machine Learning on Azure - AzureConf
 
Lecture4.pptx
Lecture4.pptxLecture4.pptx
Lecture4.pptx
 

Surviving Technical Interviews with Data Structures & Algorithms

  • 1. Surviving & Thriving in Technical Interviews Making your brain do hard things while under pressure
  • 2. Surviving & Thriving in Technical Interviews Making your brain do hard things while under pressure Why is it so hard?!
  • 3. What Are Interviewers Looking For? ü  Ability to solve problems ü  Technical skills ü  Soft Skills ü  Team Fit
  • 4. §  Understand the problem §  Think logically §  Explain Yourself §  Propose a solution §  Analyze solution §  Make improvements §  Handle changes or constraints Ability to Solve Problems
  • 5. §  Domain-specific Knowledge §  Data Structures §  Algorithms §  Design Patterns §  Dealing with Large Data Sets Technical Skills
  • 6. §  Array §  Hash Map §  Linked List §  Stack §  Queue §  Tree §  Heap §  Graph §  Searching §  Linear Search §  Binary Search §  Sorting §  Selection Sort §  Insertion Sort §  Merge Sort §  Quicksort §  Bucket Sort Data Structures & Algorithms
  • 7. §  Used to classify algorithms by their time complexity – how their processing time is affected by input size. §  Basic Classifications: Big-O Notation & Time Complexity § Constant – O(1) or O(c)   § Logarithmic – O(log  n)   § Linear – O(n)   § Linearithmic – O(n  log  n)   § Quadratic – O(n2)   § Polynomial – O(nc)   § Exponential – O(cn)   § Factorial – O(n!)  
  • 8. §  The amount of memory cells an algorithm needs. §  Often have to evaluate tradeoffs between space and time complexity §  Doing things "in-place" or not Space Complexity
  • 9. §  Communication §  Teamwork §  Leadership §  Confidence §  Responsibility See Amazon Leadership Principles - http://amzn.to/Qb6JB6 Soft Skills
  • 11. I don't mind doing interviews. I don't mind answering thoughtful questions. But I'm not thrilled about answering questions like, 'If you were being mugged, and you had a light saber in one pocket and a whip in the other, which would you use?' – Harrison Ford “ ”
  • 12. Example #1 – The Raffle §  Tickets are numbered from 1 to 1,000,000 §  Select 700,000 random winners §  No duplicates
  • 13. The Raffle – Solution #1 $winners  =  array_rand(    array_fill_keys(range(1,  1000000),  true),    700000   );  
  • 14. The Raffle – Solution #1 PROS §  Succinct §  Uses native functions §  Pretty fast §  O(n)   $winners  =  array_rand(array_fill_keys(range(1,  1000000),  true),  700000);  
  • 15. The Raffle – Solution #1 PROS §  Succinct §  Uses native functions §  Pretty fast §  O(n)   CONS §  Memory hog! §  Crashes on higher numbers §  Not very random due to how array_rand() works $winners  =  array_rand(array_fill_keys(range(1,  1000000),  true),  700000);  
  • 16. The Raffle – Solution #2 $winners  =  array();   for  ($i  =  1;  $i  <=  700000;  $i++)  {        $n  =  mt_rand(1,  1000000);        if  (isset($winners[$n]))  {              $i-­‐-­‐;        }  else  {              $winners[$n]  =  true;        }   }   $winners  =  array_keys($winners);     Note:The "mt" in mt_rand()  stands for Mersenne Twister.
  • 17. The Raffle – Solution #2 $winners  =  array();   for  ($i  =  1;  $i  <=  700000;  $i++)   {          $n  =  mt_rand(1,  1000000);          if  (isset($winners[$n]))  {                  $i-­‐-­‐;          }  else  {                  $winners[$n]  =  true;          }   }   $winners  =  array_keys($winners);   PROS §  Lower memory than #1 §  Very good randomness CONS §  Not really O(n) §  ~10x slower than #1 §  Extra step to get results
  • 18. The Raffle – Solution #3 $winners  =  range(1,  1000000);   shuffle($winners);   $winners  =  array_slice($winners,  0,  700000);     PROS §  Fast §  O(n) §  Lower memory than #1 CONS §  More random than #1, but not as random as #2
  • 19. CONS §  More random than #1, but not as random as #2 PROS §  Fast §  O(n) §  Low memory The Raffle – Solution #3 $winners  =  range(1,  1000000);   shuffle($winners);   $winners  =  array_slice($winners,  0,  700000);     How To Improve: Use a Fisher-Yates shuffle algorithm that is seeded with mt_rand().This would increase the randomness without negatively affecting performance.
  • 20. The Raffle – Follow Up What if there were 1,000,000,000 tickets?
  • 21. The Raffle – Follow Up What if there were 1,000,000,000 tickets? php  >  $r  =  range(1,  1000000000);   PHP  Fatal  error:    Allowed  memory  size  of  536870912  bytes  exhausted  
  • 22. Example #2 – Odd Duck §  Input: an array of non-negative integers §  Integers in the array all exist an even number of times §  Except for one of them… Find the "odd duck"
  • 23. Odd Duck – Before You Start §  It's OK to ask clarifying questions §  What kind of questions would you ask?
  • 24. Odd Duck – Before You Start §  It's OK to ask clarifying questions §  What kind of questions would you ask? §  Is an empty array valid? No. §  Is a single-element array valid? Yes. §  Is the array sorted? No. §  Can there be more than one instance of the "odd duck"? Yes.
  • 25. Odd Duck – Before You Start §  It's OK to ask clarifying questions §  What kind of questions would you ask? §  Is an empty array valid? No. §  Is a single-element array valid? Yes. §  Is the array sorted? No. §  Can there be more than one instance of the "odd duck"? Yes. …  8  5  42  8  8  9  1   42  1  1  8  9  5  …  
  • 26. Odd Duck – Exercise
  • 27. Odd Duck – Solutions 1.  For each number in the array, count the occurrences of that number and check if it's odd. Bad choice: O(n2)
  • 28. Odd Duck – Solutions 1.  For each number in the array, count the occurrences of that number and check if it's odd. Bad choice: O(n2)   2.  Use a 2nd array to count the occurrences of each number, then look in that 2nd array for the odd one.
  • 29. Odd Duck – Solutions 1.  For each number in the array, count the occurrences of that number and check if it's odd. Bad choice: O(n2)   2.  Use a 2nd array to count the occurrences of each number, then look in that 2nd array for the odd one. 3.  Sort the array, and then look for the first occurrence of a number that exists an odd number of times. (Bonus points: look in pairs)
  • 30. Odd Duck – Solutions 1.  For each number in the array, count the occurrences of that number and check if it's odd. Bad choice: O(n2)   2.  Use a 2nd array to count the occurrences of each number, then look in that 2nd array for the odd one. 3.  Sort the array, and then look for the first occurrence of a number that exists an odd number of times. (Bonus points: look in pairs) 4.  Use a 2nd array.When you encounter a number, add it to the 2nd array (as the key).When you encounter it again, remove/unset it.
  • 31. Odd Duck – Solutions 1.  For each number in the array, count the occurrences of that number and check if it's odd. Bad choice: O(n2)   2.  Use a 2nd array to count the occurrences of each number, then look in that 2nd array for the odd one. 3.  Sort the array, and then look for the first occurrence of a number that exists an odd number of times. (Bonus points: look in pairs) 4.  Use a 2nd array.When you encounter a number, add it to the 2nd array (as the key).When you encounter it again, remove/unset it. 5.  XOR all of the array elements together. (Oh…)
  • 33. Preparing for the Questions §  Research your potential employer §  Be familiar with your own résumé §  Review the job description §  Practice technical interview questions §  Review data structures and algorithms §  Be prepared for behavioral questions
  • 34. Behavioral Questions §  Questions related to past experiences §  "Give me an example of a time when…" §  "Tell me about something you did that…" §  "How do you handle a situation where…" §  Plan some good experiences to share §  Talk about "I", not "we", and be honest §  Be prepared to give details
  • 35. Physical Preparations §  Be well-rested §  Arrive early §  Use the restroom before the interview §  Turn off your phone §  Assume business casual dress unless you are told otherwise
  • 36. Interview Tips §  Don't Panic §  Ask Questions §  Don't Be Evasive §  ShowYour Skills §  Be Positive §  Learn Something
  • 37. Any Questions? Presentation by Jeremy Lindblom @jeremeamia Thanks!