surviving and thriving in technical interviews

37
Surviving & Thriving in Technical Interviews Making your brain do hard things while under pressure

Upload: jeremy-lindblom

Post on 05-Dec-2014

342 views

Category:

Documents


2 download

DESCRIPTION

Technical interviews can a difficult and stressful part of finding employment. Regardless of whether or not you receive the job offer, you can make the technical interview process a good experience every time. In this session, you will learn some tips for your next technical interview, and also analyze some example interview and coding questions to learn how to think about and answer questions in a way that shows off your abilities.

TRANSCRIPT

Page 1: Surviving and Thriving in Technical Interviews

Surviving & Thriving in Technical Interviews

Making your brain do hard things while under pressure

Page 2: Surviving and Thriving in Technical Interviews

Surviving & Thriving in Technical Interviews

Making your brain do hard things while under pressure

Why is it so hard?!

Page 3: Surviving and Thriving in Technical Interviews

What Are Interviewers Looking For?

ü  Ability to solve problems

ü  Technical skills

ü  Soft Skills

ü  Team Fit

Page 4: Surviving and Thriving in Technical Interviews

§  Understand the problem

§  Think logically

§  Explain Yourself

§  Propose a solution

§  Analyze solution

§  Make improvements

§  Handle changes or constraints

Ability to Solve Problems

Page 5: Surviving and Thriving in Technical Interviews

§  Domain-specific Knowledge

§  Data Structures

§  Algorithms

§  Design Patterns

§  Dealing with Large Data Sets

Technical Skills

Page 6: Surviving and Thriving in Technical Interviews

§  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

Page 7: Surviving and Thriving in Technical Interviews

§  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!)  

Page 8: Surviving and Thriving in Technical Interviews

§  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

Page 9: Surviving and Thriving in Technical Interviews

§  Communication

§  Teamwork

§  Leadership

§  Confidence

§  Responsibility

See Amazon Leadership Principles - http://amzn.to/Qb6JB6

Soft Skills

Page 10: Surviving and Thriving in Technical Interviews

Technical Interview Question Examples

Page 11: Surviving and Thriving in Technical Interviews

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

Page 12: Surviving and Thriving in Technical Interviews

Example #1 – The Raffle

§  Tickets are numbered from 1 to 1,000,000

§  Select 700,000 random winners

§  No duplicates

Page 13: Surviving and Thriving in Technical Interviews

The Raffle – Solution #1

$winners  =  array_rand(    array_fill_keys(range(1,  1000000),  true),    700000  

);  

Page 14: Surviving and Thriving in Technical Interviews

The Raffle – Solution #1

PROS

§  Succinct

§  Uses native functions

§  Pretty fast

§  O(n)  

$winners  =  array_rand(array_fill_keys(range(1,  1000000),  true),  700000);  

Page 15: Surviving and Thriving in Technical Interviews

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);  

Page 16: Surviving and Thriving in Technical Interviews

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.

Page 17: Surviving and Thriving in Technical Interviews

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

Page 18: Surviving and Thriving in Technical Interviews

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

Page 19: Surviving and Thriving in Technical Interviews

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.

Page 20: Surviving and Thriving in Technical Interviews

The Raffle – Follow Up

What if there were 1,000,000,000 tickets?

Page 21: Surviving and Thriving in Technical Interviews

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  

Page 22: Surviving and Thriving in Technical Interviews

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"

Page 23: Surviving and Thriving in Technical Interviews

Odd Duck – Before You Start

§  It's OK to ask clarifying questions

§  What kind of questions would you ask?

Page 24: Surviving and Thriving in Technical Interviews

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.

Page 25: Surviving and Thriving in Technical Interviews

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  …  

Page 26: Surviving and Thriving in Technical Interviews

Odd Duck – Exercise

Page 27: Surviving and Thriving in Technical Interviews

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)

Page 28: Surviving and Thriving in Technical Interviews

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.

Page 29: Surviving and Thriving in Technical Interviews

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)

Page 30: Surviving and Thriving in Technical Interviews

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.

Page 31: Surviving and Thriving in Technical Interviews

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…)

Page 32: Surviving and Thriving in Technical Interviews

Preparation and Tips

Page 33: Surviving and Thriving in Technical Interviews

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

Page 34: Surviving and Thriving in Technical Interviews

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

Page 35: Surviving and Thriving in Technical Interviews

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

Page 36: Surviving and Thriving in Technical Interviews

Interview Tips

§  Don't Panic

§  Ask Questions

§  Don't Be Evasive

§  Show Your Skills

§  Be Positive

§  Learn Something

Page 37: Surviving and Thriving in Technical Interviews

Any Questions?

Presentation by Jeremy Lindblom

@jeremeamia

Thanks!