Amazon | L6 | Onsite | Terrible Interview (USA)
Amazon Interview Write Up
The interview experience was terrible.
The recruiter set me up for 3 interviews on the first day and 2 interviews on the second day. Amazon cancelled the second day and somehow couldn't reschedule for over a month. My first interview was in one month, and my second interview was in the middle of the next month.
Overall advice I have is that:
Interview 1:
This guy was HORRIBLE. I could not understand his English at all. My company name sounds similar to a Python package name, and after I told him my LP stories, he asked me if I work at the place that make the Python package. He wasn't even listening to what I said when I told him what my company does or what I do.
A time where I took on something significant outside my area of responsibility. Why is it important?
A time where I strongly disagreed on my manager or peer.
Coding question (Note the bad English):
1You are in platform team. Various internal teams have been asking for a central place to store customer preferences in the form of attribute.
2When a client try to access a preference (read/write)
31. The client must have the permission to do perform the operation(read/write) on the preference.
42. The value need to be verified before it's stored in the database. Let’s say the value needs to conform to a constraint (e.g., regex pattern, range of number, valid chars).
5
6Given access to database (set/get preference), you task is to provide the low-level code for two functionalities
7* getCustomerPreferenceValue(clientId, customerId, attributeName)
8* setCustomerPreferenceValue(clientId, customerId, attributeName, attributeValue)
9
10You decided the type of the parameters/return value.
11
12public class PreferenceService {
13
14/* Consider this as a ready to use object.
15 * db.getPreference(customerId, attributeName);
16 * db.setPreference(customerId, attributeName, attributeValue);
17 */
18
19 private DataBaseAPI db;
20
21 // You can modify any param/result type in the method definition
22
23 public Attribute getCustomerPreferenceValue(String clientId, String customerId, String attributeName);
24
25 // You can modify any param/result type in the method definition
26
27 public void setCustomerPreferenceValue(String clientId, String customerId, String attributeName, String attributeValue)
28
29 }
30}
31
32
33/* Consider this as a ready to use object.
34 * db.getPreference(customerId, attributeName);
35 * db.setPreference(customerId, attributeName, attributeValue);
36 */I asked what you use the clientId for, and he said he didn't know. He said I can ignore it.
After I wrote the code for getCustomerPreferenceValue, he asked me why I wasn't using clientId.
He asked me what happens in setCustomerPreferenceValue if there is no previous value in the DB. I told him it's an UPSERT (update or insert) and it will create a new value if it doesn't already exist. He said he wants me to write two separate methods: one for update, one for insert.
I wrote both methods, and then he acted confused and said why would you write two different methods?
We ran out of time. I asked him to clarify what he was asking, and he told me to forget about it. This happened over and over.
Interview 2:
Most innovative thing I've done and why?
Talk about something that needed in depth thought and analysis.
Coding:
How many binary trees are there with N nodes?
Assume all nodes are unlabeled/identical, i.e. swapping any two nodes in a given tree results in the same tree.
He did not provide me with the trees, so I had to make them myself. This is BAD, as you can make a mistake in figuring out the relationship. It becomes clear n = 4.
1A
2 \
3 B
4
5 B A
6 / == /
7A B
8--------
9 B
10 / \
11A C
12
13 B
14 /
15 A
16 /
17 C
18
19
20 B
21 /
22 A
23 \
24 C
25
26 B
27 \
28 A
29 /
30 C
31
32 B
33 \
34 A
35 \
36 C
37
381 -> 1
392 -> 2
403 -> 5
414 -> 14
425 -> 42I figured out the code for this. The relationship is: numTrees(n) = sum(numTrees(k) * numTrees(n - 1 - k)) for k in range(n)
Interview 3: Bar raiser
4 LPs.
Interview 4: System Design.
A time where I needed peer cooperation and they were resistant.
A time where I couldn't meet a timeline.
A time where I had to manage multiple obstacles to deliver.
System Design:
Amazon offers a chatbot. The chatbot takes user input and figures out which service to route the request to (e.g. shopping requests should be routed to the shopping service). The service computes the response and we want to give it back to the customer.
System APIs.
Data Schema
Talk about system housekeeping like Metrics, Analytics, Telemetry, Logging, Alerting.
Follow up:
We want to save all the answers given back to the users and store them for later analysis. Design components for this.
I said we can use Postgres at very low scales (e.g. 100s of writes / second) and we can shard on user_id if need be, but we'd likely need to use something with better horizontal scaling like DynamoDB if we have higher write traffic. We can even extend the usefulness of Postgres by putting Kafka in front of it to manage the traffic and perform the writes later.
The interviewer seemed happy. Remember, you only get 30 minutes for these system design interviews.
Interview 5: Coding
This is the other interview I was extremely unhappy about. The recruiter warned me that you need to give the optimal solution.
A time when I did have enough information to make a decision.
A time when I made a bad decision.
A time when I took work outside my comfort area.
Coding Question:
1/**
2Given a log of website requests,
3where each request entry contains (time, customerId, page visited).
4Find the most visited n-consecutive page sequence. Where n can vary.
5*/I immediately said that a rolling hash was the best solution. It is O(n) to parse the entire string, and it's O(n) to find the most frequent log. (THIS IS CORRECT).
He said he wants me to use brute force instead.
1def most_visited_sequence(log_list: List[Log], n: int) -> List[str]:
2 customer_id_to_pages_visited = defaultdict(list)
3 log_list.sort(key=lambda log : log.time)
4 for log in log_list:
5 customer_id_to_pages_visited[log.customerId].append(log.pageVisited)
6 sequenceToFrequency = defaultdict(int)
7 highestFrequency = 0
8 mostFrequentSubsequences = []
9 for pageVisited in customer_id_to_pages_visited.values():
10 numLogs = len(pageVisited)
11 if numLogs < n:
12 continue
13 for start in range(numLogs - n):
14 key = tuple(item.pageVisited for item in pageVisited[start: start + n])
15 sequenceToFrequency[key] += 1
16 if sequenceToFrequency[key] > highestFrequency:
17 mostFrequentSubsequence = [key]
18 highestFrequency = sequenceToFrequency[key]
19 elif sequenceToFrequency[key] == highestFrequency:
20 mostFrequentSubsequences.append(key)
21 return mostFrequentSubsequences After this, he said he wants me to make it faster. I talked about using a rolling hash. He said don't use a rolling hash.
I mentioned that you could use a prefix trie. He liked this idea, but it's not faster.
This interview was also confusing, but not as confusing as the first.
Overall result:
No hire for senior, offer for L5. I rejected it. This was a terrible experience.