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