Skip to content

Commit ee1c28a

Browse files
committed
Adding day progress of day 9961
1 parent 65ce01f commit ee1c28a

File tree

1 file changed

+261
-0
lines changed

1 file changed

+261
-0
lines changed
Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
---`
2+
layout: post
3+
title: "Day progress 9961"
4+
date: "2019-09-26 17:44:46 +0530"
5+
tags:
6+
- amazon
7+
- interview
8+
- hyderabad
9+
---
10+
11+
## Morning
12+
13+
I slept around 2:00 AM Yesterday. I was preparing for non-technical questions
14+
and it took little late for me to go to bed. Despite sleeping late I had to wake
15+
up at 7:30 AM anyhow. If I do any delay than this, then I might had difficulty
16+
in reaching for the Amazon office.
17+
18+
19+
## First half
20+
21+
22+
### Amazon on-site interview
23+
24+
25+
#### First round
26+
27+
First round was Data structure and Algorithm round. This round was taken by an
28+
Amazon employee who was working from Amazon Hyderabad centre before and then
29+
he transferred to Amazon Seattle centre.
30+
31+
32+
##### Question
33+
34+
You have given two strings and a set of words. You can replace any string from
35+
given set of words if they are only differ by one character. You have to give
36+
minimum number of replaces required to match both strings.
37+
38+
For example given two strings are "hot" and "cog" and "lit", "lot", "cit", "cot", "hit", "cog" are part of words.
39+
40+
Now below is a graph of all possibilities if we start replacing one string with
41+
another from a given list of words. Our goal is to return the minimum number of
42+
replaces.
43+
44+
1. "hot" -> "hit" -> "lit" -> "lot" -> "cot" -> "cog"
45+
46+
2. "hot" -> "hit" -> "lit" -> "cit" -> "cot" -> "cog"
47+
48+
3. "hot" -> "hit" -> "lit" -> "cit" -> "cot" -> "cog"
49+
50+
4. "hot" -> "hit" -> "lit" -> "cit" -> "cot" -> "lot" -> None
51+
52+
5. "hot" -> "lot" -> "cot" -> "cog"
53+
54+
Here minimum solution is number 5 because it only takes 4 swaps of string.
55+
56+
57+
##### My approach
58+
59+
It took some time to understand this question. After discussing for a bit, I
60+
mentioned that we can compare if two strings are similar by one different
61+
characters using hash table approach. He instructed me to first write that
62+
function. So I wrote a function which returns a boolean value that weather given
63+
strings are not different than two characters.
64+
65+
Then he instructed me to compose my final code. I mentioned him aurally that I
66+
can compute this by using backtracking approach in which I remove one string and
67+
then increase a count.
68+
69+
We can break when two strings are equal or there are no more words left. When we
70+
break we also check weather given number of swaps is minimum then our string.
71+
72+
He then instructed me to wrote a code for it. I wrote a backtrack code in which
73+
I wrote code as per our discussion. Then he tried to check the flow of my code
74+
and said that it looks like it will work.
75+
76+
Then he said he has already more minutes than decided so he want to end. He
77+
asked me that if I have any questions for him. He said that rather going for
78+
each and every branch given problem can be improved in which it doesn't go for
79+
each branch and it will return a value.
80+
81+
I thought for bit and then told that rather than going with Depth first approach
82+
I could have gone with Breadth first approach. He smiled and told me that I
83+
should think later about this problem. He also mentioned that I should not worry
84+
and be relaxed.
85+
86+
When I look this problem now I feel it can be improved using Dynamic programming
87+
because minimum sequence from given string is always limited. If we store it, we
88+
can reduce our computations based on it. But I didn't got his hint during my
89+
interview.
90+
91+
92+
#### Second question
93+
94+
This round was taken by an engineering manager. He first discussed about my
95+
existing experiences and asked few non technical questions.
96+
97+
One question from these was which is my favourite programming language and
98+
requested me to mention disadvantages of it.
99+
100+
TODO: Write your answers
101+
102+
103+
##### Question
104+
105+
I have to write a method which takes long DNA string as an input. DNA string is
106+
only sequence of 4 characters LGTA. Given list of sub strings, I have to match
107+
given characters of DNA with list of strings.
108+
109+
##### Answer
110+
111+
I took some time to understand the problem. During this process he mentioned
112+
that because given DNA string is too long, I have to come up with an approach in
113+
which I iterate on given DNA string and I can also match which sub strings are
114+
matched.
115+
116+
His this hint clicked me that this is a problem of Trie. After thinking a bit I
117+
told him that this can be solved better using Trie data structure. He told me to
118+
first define class for Node of Trie. I created and and mentioned that Node will
119+
point to next node. If it is null then we can say that this reached to end. We
120+
can also put one more variable called "end" to indicate that given key ends
121+
here.
122+
123+
Then he mentioned me to describe Trie aurally. I describe how comparision of
124+
keys we can do and he agreed to my approach.
125+
126+
Then he said that I should implement code for method and assume Trie is present.
127+
I just have to call API functions of Trie.
128+
129+
We add pointer to head of a string. Responsibility of pointer is to track how
130+
many character from given DNA string we can match from our group.
131+
132+
We iterate on each character from DNA string and iterate throw each pointers. If
133+
current DNA character is equal next of pointer then we increase pointer to its
134+
next node. At the end we start
135+
136+
We first manage collection of pointers. If a pointer is at end then we can tell
137+
that a string is matched.
138+
139+
I mention that we can manage pointer to a node and while iterating on DNA
140+
sequence we can
141+
142+
I coded a function in which I create a pointer for matching existing string. If
143+
nothing is found, we start matching for string from the beginning of Trie.
144+
145+
My code was confusing I told that there is huge chance to improve it. He said it
146+
is okay. He tried to went with the flow and said it looks it will work.
147+
148+
Then he said how will I get sequence of DNA characters?
149+
150+
I said I will just call that function. He said okay this looks good.
151+
152+
At the time of writing this post, I think I was missing one important point he
153+
mentioned earlier. He mentioned that sequence of DNA is too huge I can't load it
154+
into memory. I think I have to came up with any better solution in which I
155+
iterate given DNA sequence not in one rather divide it in batches, but I didn't
156+
showed any of these improvements in my interview. I could have improved this.
157+
158+
159+
#### Third round
160+
161+
Interviewer started by asking couple of non technical questions.
162+
163+
##### Question
164+
165+
This was a system design round. I was asked to define a resturent reservation
166+
system. In this system a user can reserve a table from on-line app or by walking
167+
to the restaurent. He told me to explain the flow of the system first.
168+
169+
I started by mentioning various entities of the system. I then explained a flow
170+
of online and walking customer. He was having a few questions based on it. Then
171+
I draw schema diagrams of reservations.
172+
173+
Then he asked couple of questions based on it. He mentioned that how will I
174+
handle a case in which one user is booking a table and another user is also
175+
booking the same table at the same time.
176+
177+
I mentioned then there will be a different state of the system. In this case, we
178+
can manage a global cache service which takes table id, restaurent id for making
179+
it into block stage for a while. We can update blocked or un blocked states to
180+
User may be when they first loads a system or improved will be to send server
181+
sent events to client.
182+
183+
As a followup questions he said that there is possibility that this cache become
184+
too much huge and it will be stayed in memory. It is possible that we can go
185+
overload by memory. I said that then we can use shrading for distributing our
186+
caches to other work stations to achieve horizontal scaling. And I also added
187+
that we can manage replicas for each shred we can use that as a fallback
188+
mechanism in which if given shard fails we have working worsion if it available.
189+
190+
He agreed with my approach and said that he want to conclude this interview.
191+
While he was winding, I request him to provide any feedback on my solutions. He
192+
said he liked my approach, he also said that I went for schema diagram based
193+
approach and that is also a good thing to do. He mentioned some improvements
194+
that I forgot somehow.
195+
196+
At the time of writing this blog post, I realized that I have done one big
197+
mistake in my system design diagram. I haven't mentioned webserver in my system.
198+
This mistake I keep do while ploting my system design solution. It is a big
199+
mistake. After this, I will always mention webserver as one of my component in
200+
system.
201+
202+
203+
#### Fourth round
204+
205+
This round was object oriented design round. First she asked me couple of
206+
questions related to my experience and requested me to define a situation where
207+
I think I could have done better. This was tough one. I thought for various
208+
examples and then I tried to look to it.
209+
210+
She was confused on one of my solution and then we keep discussion things on Git
211+
couple of minutes. It was around 15 minutes. I think I was not able to explain
212+
her clearly or may be she thought she had understood and I am the one who is
213+
making mistake.
214+
215+
In my past experience, I had lost my tempre. This time I was controlling my
216+
self. It was hard for me to control and don't be ancious. Finally, she got my
217+
point and then she also mentioned that I didn't did something interesting. She
218+
mentioned that I have done something very basic stuff. This was a reaction of
219+
all interviwers. Because it is a role for seniour position, a recruiter has
220+
already mentioned that I should have some good experience of ledership and
221+
training people. So far they are right here. I don't think I have a strong
222+
experience of working at some large system and more client centric.
223+
224+
Then she mentioned that she has very less time to go with System design
225+
question.
226+
227+
#### Question
228+
229+
I have to design a system for managing inventory management for scale of Amazon.
230+
There can be various ware houses which are located at different locations.
231+
Inventory is responsible for managing various items and their quantities.
232+
233+
#### Answer
234+
235+
I started writing an interface for Item and then wrote concrite factory method
236+
and the time for given slot was up. I defined a class for each item category.
237+
238+
She said I have 5 minutes in which I have to explain here how will I manage
239+
items in given inventory. I said I will store items by their category into a
240+
hash map. And store items as sub hash map by their id.
241+
242+
She said that she is interested in identifying how will I manage my inventory
243+
when there are many var houses.
244+
245+
Her ultimate goal was to provide an search for items by its name and my approach
246+
in which how I provide a search operation to it.
247+
248+
She explained a solution quickly by saying that one more hash map which stores
249+
location of items by its type and have reference to each ware houses which again
250+
has our previous implementation of items. I am not sure this was the exact
251+
solution but it was something similar to this.
252+
253+
When she was wrapping up, I asked her to get a review on my approach. She said
254+
she was expecting me to have managers for each items and inventories. And she
255+
was interested in knowing my iteractions of item, inventory and warehouse.
256+
257+
She didn't mentioned that my approach was good, okay or anything else. I asked
258+
her how my approach felt to her. She said my factory and item type implemtation
259+
works.
260+
261+
Her this remarks felt me sad. I don't think she was happy with my appraoch.

0 commit comments

Comments
 (0)