0% found this document useful (0 votes)
276 views11 pages

SDE Tech Prep Resource

Uploaded by

arjitmadan96
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
276 views11 pages

SDE Tech Prep Resource

Uploaded by

arjitmadan96
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Amazon Confidential

Guide To Successfully Answering Technical Questions


Best Practices when answering Tech Questions:

 Start by asking clarifying questions – make sure you understand the problem by gathering
the requirements and discussing use cases
 Don't worry; this problem can be medium - hard complexity. You’ll have 30-35 minutes to
work on it.
 Your priorities are:
o Correctness - Code should be syntactically/logically correct.
o Code must be simple – easy to read, easy to test, maintain, debug, and enhance
o No Brute Force or Pseudocode Solution, you must come up with the best optimal
solution (final goal). In case you start with Brute Force or pseudocode make sure
you are optimizing the solution by the end of the coding round. If you are only
able to come up with a solution that requires Brute Force - code your solution
because a Brute Force Solution is better than no solution at all.
o Verify/Validate your code. Consider all the edge cases - as you identify edge cases
ask your interviewer if the edge case needs to be addressed - this can save you
code and brain power
 You are being evaluated based on your ability to problem solve, write maintainable and
scalable code and how close to production ready your solution is
 It’s ok to ask questions if you are stuck, listen to the interviewer’s hints when given.
 Be ready to explain your thought process before, during and after the coding portion of
the interview

When you are working to solve technical questions it is best to have a process to work through –
here is a methodology that many candidates have found successful:

Problem Solving Methodology:

1. Clarify the Question - ask clarifying questions to make sure you understand all the
variables and address any ambiguity – Ideal time - 2 minutes
2. Rephrase the Question - Repeat the question back in your own words so the interviewer
knows you understand the problem, highlight the signature, the inputs you are given and
what type of method or function you will be using – Ideal time 1 minute
3. Layout the Algorithm - In order to save time and optimize communication write down
your algorithm either before or as you review it with your interviewer. Make sure you
state time complexity and have your interviewer agree – Ideal time 3 - 4 minutes
4. Write your code — I have found it is hard to talk and code so for best performance let
the interviewer know you are going to focus on Coding for the next 10-15 minutes.
5. Review your code - Optimize, validate, identify edge cases, fix any bugs, test your code
and discuss where future enhancements might arise with your interviewer. Ideal time – 5
minutes
1
Amazon Confidential

Types of Coding Questions to Expect:


• Coding (logical and maintainable) – the test is to see if you can write simple code – easy to
maintain, organized in a way it is easy to read and understand & easy to test
• Coding: Data Structures and Algorithms - choose the right data structure to solve the problem
and come up with best optimal solution – discuss tradeoffs – why you choose one over the other
• Coding: Problem Solving - – there will be ambiguity – Ask really good clarifying questions - make
sure you justify why you chose the data structure, have to solve the problem, identify tradeoffs
with several different solutions. Think thru the perimeter of the problem when there is
ambiguity
• System Design (API, Storage, Communication, scalability and operational performance) – the
goal is to convey you know how to design & build the components for a system, can speak to the
upside vs down side, Amazon is looking for someone who can scale a system, discuss availability,
reliability and scalability --- make sure the design is operational – you need to be able to take
code to production – make sure quality of code is high, low latency or fault tolerance – should be
setting up rules for all of those

Additional Tips for succeeding in coding rounds:


• ASK QUALIFYING QUESTIONS IN EACH ROUND – I capitalized this because it is the number one
mistake engineers make on the technical portion of our interviews
• Make sure you create an optimal solution—if you brute force/pseudo code a solution make
sure you work to optimize it
• Brush up on Algorithms and Data Structures
• Cover all your edge cases/corner cases
• Come up with “Optimal Solutions” (don’t use brute force or pseudo code). You can code in any
language you wish
• Be aware of the different time/space complexities of each problem
• Review understanding of the inner workings of common data structures and be able to
compare / contrast their usage in various applications
• Consider reviewing common algorithms such as traversals, divide and conquer, breadth-first
search vs. depth-first search
• Be sure to be able to talk about O(N) Complexities/Big O, Edge and corner test cases, and
ALWAYS code in a clean eloquent way (no brute force solutions).

2
Amazon Confidential

Sample Technical Questions:

These questions are designed to test your Problem Solving Ability, knowledge of data structures &
algorithms and if you can write logical and maintainable code.

1. Counting Analogous Arrays – Time to solve – 18 minutes

A covert agent has some crucial information stored in the form of an array of integers. The array
contains sensitive information and it must not be revealed to anyone. However, there are few
things about the array which are known.

An array is said to be analogous to the secret array if all of the following conditions are true:
 The length of the array is equal to the length of the secret array.
 Each integer in the array lies in the interval [lowerBound, upperBound].
 The difference between each pair of consecutive integers of the array must be equal to the
difference between the respective pair of consecutive integers in the secret array. In other
words, let the secret array be [s[0], s[1],...s[n-1]]and let the analogous array be [a[0], a[1],...a[n-
1]], then (a[i-1] - a[i]) must be equal to (s[i-1] - s[i]) for each i from 1 to n-1.

Given the value of the integers lowerBound and upperBound, inclusive, and the array of
differences between each pair of consecutive integers of the secret array, find the number of
arrays that are analogous to the secret array. If there is no array analogous to the secret array,
return 0.

For example:
consecutiveDifference = [-2, -1, -2, 5]
lowerBound=3
upperBound=10

The logic to create an analogous array starting from the lower bound is:
Start with a value of 3.
Subtract consecutiveDistances[0], 3 - (-2) = 5
Subtract consecutiveDistances[1], 5 - (-1) = 6
Subtract consecutiveDistances[2], 6 - (-2) = 8
Subtract consecutiveDistances[3], 8 - 5 = 3

Note that none of the values is out of bounds. All possible analogous arrays are:
3
Amazon Confidential

[3, 5, 6, 8, 3]
[4, 6, 7, 9, 4]
[5, 7, 8, 10, 5]

The answer is 3.

Function Description
Complete the function countAnalogousArrays in the editor below.

countAnalogousArrays has the following parameter(s):


int consecutiveDifference[n]: the differences between each pair of consecutive integers in the
secret array
int lowerBound: an integer
int upperBound: an integer
Returns:
int: the number of arrays that are analogous to the secret array

Constraints
 -109 ≤ lowerBound ≤ upperBound ≤ 109
 1 ≤ n ≤ 105
 -2*109 ≤ consecutiveDifference[i] ≤ 2*109

2. Optimizing Box Weights

An Amazon Fulfillment Associate has a set of items that need to be packed into two boxes. Given an integer
array of the item weights (arr) to be packed, divide the item weights into two subsets, A and B, for packing into
the associated boxes, while respecting the following conditions:

 The intersection of A and B is null.


 The union A and B is equal to the original array.
 The number of elements in subset A is minimal.
 The sum of A's weights is greater than the sum of B's weights.

Return the subset A in increasing order where the sum of A's weights is greater than the sum of B's weights. If
more than one subset A exists, return the one with the maximal total weight.

4
Amazon Confidential

Example
n=5
arr = [3, 7, 5, 6, 2]

The 2 subsets in arr that satisfy the conditions for A are [5, 7] and [6, 7] :
 A is minimal (size 2)
 Sum(A) = (5 + 7) = 12 > Sum(B) = (2 + 3 + 6) = 11
 Sum(A) = (6 + 7) = 13 > Sum(B) = (2 + 3 + 5) = 10
 The intersection of A and B is null and their union is equal to arr.
 The subset A where the sum of its weight is maximal is [6, 7].

Function Description
Complete the minimalHeaviestSetA function in the editor below.

minimalHeaviestSetA has the following parameter(s):


int arr[]: an integer array of the weights of each item in the set

Returns:
int[] : an integer array with the values of subset A

Constraints
 1 ≤ n ≤ 105
 1 ≤ arr[i] ≤ 105 (where 0 ≤ i < n)

3. Robot Rodeo

An Amazon Fulfillment Associate has a set of items that need to be packed into two boxes. Given an integer
array of the item weights (arr) to be packed, divide the item weights into two subsets, A and B, for packing into
the associated boxes, while respecting the following conditions:

 The intersection of A and B is null.


 The union A and B is equal to the original array.
 The number of elements in subset A is minimal.
 The sum of A's weights is greater than the sum of B's weights.

Return the subset A in increasing order where the sum of A's weights is greater than the sum of B's weights. If
more than one subset A exists, return the one with the maximal total weight.

5
Amazon Confidential

Example
n=5
arr = [3, 7, 5, 6, 2]

The 2 subsets in arr that satisfy the conditions for A are [5, 7] and [6, 7] :
 A is minimal (size 2)
 Sum(A) = (5 + 7) = 12 > Sum(B) = (2 + 3 + 6) = 11
 Sum(A) = (6 + 7) = 13 > Sum(B) = (2 + 3 + 5) = 10
 The intersection of A and B is null and their union is equal to arr.
 The subset A where the sum of its weight is maximal is [6, 7].

Function Description
Complete the minimalHeaviestSetA function in the editor below.

minimalHeaviestSetA has the following parameter(s):


int arr[]: an integer array of the weights of each item in the set

Returns:
int[] : an integer array with the values of subset A

Constraints
 1 ≤ n ≤ 105
 1 ≤ arr[i] ≤ 105 (where 0 ≤ i < n)

4. Shopping Options

An Amazon customer wants to buy a pair of jeans, a pair of shoes, a skirt, and a top but has a limited budget in
dollars. Given different pricing options for each product, determine how many options our customer has to
buy 1 of each product. You cannot spend more money than the budgeted amount.

Example
priceOfJeans = [2, 3]
priceOfShoes = [4]
priceOfSkirts = [2, 3]
priceOfTops = [1, 2]
budgeted = 10

6
Amazon Confidential

The customer must buy shoes for 4 dollars since there is only one option. This leaves 6 dollars to spend on the
other 3 items. Combinations of prices paid for jeans, skirts, and tops respectively that add up to 6 dollars or
less are [2, 2, 2], [2, 2, 1], [3, 2, 1], [2, 3, 1]. There are 4 ways the customer can purchase all 4 items.

Function Description

Complete the getNumberOfOptions function in the editor below. The function must return an integer which
represents the number of options present to buy the four items.

getNumberOfOptions has 5 parameters:


int[] priceOfJeans: An integer array, which contains the prices of the pairs of jeans available.
int[] priceOfShoes: An integer array, which contains the prices of the pairs of shoes available.
int[] priceOfSkirts: An integer array, which contains the prices of the skirts available.
int[] priceOfTops: An integer array, which contains the prices of the tops available.
int dollars: the total number of dollars available to shop with.

Constraints
 1 ≤ a, b, c, d ≤ 103
 1 ≤ dollars ≤ 109
 1 ≤ price of each item ≤ 109
Note: a, b, c and d are the sizes of the four price arrays

5. Algorithm Swap

You're a new Amazon Software Development Engineer (SDE). You're reading through your team's code and
find an old sorting algorithm. The following algorithm is used to sort an array of distinct n integers:

For the input array arr of size n do:

 Try to find the smallest pair of indices 0 ≤ i < j ≤ n-1 such that arr[i] > arr[j]. Here smallest means usual
alphabetical ordering of pairs, i.e. (i1, j1) < (i2, j2) if and only if i1 < i2 or (i1 = i2 and j1 < j2).
 If there is no such pair, stop.
 Otherwise, swap a[i] and a[j] and repeat finding the next pair.

7
Amazon Confidential

The algorithm seems to be correct, but the question is how efficient is it? Write a function that returns the
number of swaps performed by the above algorithm.

For example, if the initial array is [5,1,4,2], then the algorithm first picks pair (5,1) and swaps it to produce
array [1,5,4,2]. Next, it picks pair (5,4) and swaps it to produce array [1,4,5,2]. Next, pair (4,2) is picked and
swapped to produce array [1,2,5,4], and finally, pair (5,4) is swapped to produce the final sorted
array [1,2,4,5], so the number of swaps performed is 4.

Function Description
Complete the function howManySwaps in the editor below. The function should return an integer that
denotes the number of swaps performed by the proposed algorithm on the input array.

The function has the following parameter(s):


arr: integer array of size n with all unique elements

Constraints
 1 ≤ n ≤ 105
 1 ≤ arr[i] ≤ 109
 all elements of arr are unique

6. Optimizing Box Weights

An Amazon Fulfillment Associate has a set of items that need to be packed into two boxes. Given an integer
array of the item weights (arr) to be packed, divide the item weights into two subsets, A and B, for packing into
the associated boxes, while respecting the following conditions:

 The intersection of A and B is null.


 The union A and B is equal to the original array.
 The number of elements in subset A is minimal.
 The sum of A's weights is greater than the sum of B's weights.

8
Amazon Confidential

Return the subset A in increasing order where the sum of A's weights is greater than the sum of B's weights. If
more than one subset A exists, return the one with the maximal total weight.

Example
n=5
arr = [3, 7, 5, 6, 2]

The 2 subsets in arr that satisfy the conditions for A are [5, 7] and [6, 7] :
 A is minimal (size 2)
 Sum(A) = (5 + 7) = 12 > Sum(B) = (2 + 3 + 6) = 11
 Sum(A) = (6 + 7) = 13 > Sum(B) = (2 + 3 + 5) = 10
 The intersection of A and B is null and their union is equal to arr.
 The subset A where the sum of its weight is maximal is [6, 7].

Function Description
Complete the minimalHeaviestSetA function in the editor below.

minimalHeaviestSetA has the following parameter(s):


int arr[]: an integer array of the weights of each item in the set

Returns:
int[] : an integer array with the values of subset A

Constraints
 1 ≤ n ≤ 105
 1 ≤ arr[i] ≤ 105 (where 0 ≤ i < n)

7. Storage Optimization

Amazon is experimenting with a flexible storage system for their warehouses. The storage unit consists of a
shelving system which is one meter deep with removable vertical and horizontal separators. When all
separators are installed, each storage space is one cubic meter (1' x 1' x 1'). Determine the volume of the
largest space when a series of horizontal and vertical separators are removed.

Example
n=6

9
Amazon Confidential

m=6
h = [4]
v = [2]

Consider the diagram below. The left image depicts the initial storage unit with n = 6 horizontal and m = 6
vertical separators, where the volume of the largest storage space is 1 × 1 x 1. The right image depicts that unit
after the fourth horizontal and second vertical separators are removed. The maximum storage volume for that
unit is then 2 × 2 x 1 = 4 cubic meters:

Function Description
Complete the function storage in the editor below.

storage has the following parameter(s):


int n: integer, the number of horizontal separators initially
int m: integer, the number of vertical separators initially
int h[x]: an array of integers, the horizontal separators to remove
int v[y]: an array of integers, the vertical separators to remove
Returns:
int: a long integer denoting the volume of the largest item that can be stored in the unit.

Constraints
 1 ≤ n, m ≤ 105
 0<x≤n
 0<y≤m

10
Amazon Confidential

 1 ≤ h[i] ≤ n, where 1 ≤ i ≤ n.
 1 ≤ v[j] ≤ m, where 1 ≤ j ≤ m.
 The values in array h are distinct.
 The values in array v are distinct.

8. Valet Parking Garage Design:

I run a parking garage that provides valet parking service. When a customer drives up to the entrance
they are given a ticket they can use to later collect their car and their car is parked for them somewhere
in the garage.

Design a program that can track usage of the garage and issue these tickets.

9. Data Structures and Algorithms Focused questions


1. Let's build a library with two APIs: one to ingest data and one to retrieve the
running median of that data.
10 Write a class and associated methods to
2. Track heard utterances/phrases and
3. Return the top 100 utterances in descending order of popularity

11

You might also like