## Amazon Interview Question for SDE1s

Country: India
Interview Type: In-Person

Comment hidden because of low score. Click to expand.
2
of 2 vote

use TRIE
===============
wwwDOTgeeksforgeeks.org/trie-insert-and-search/+&cd=1&hl=en&ct=clnk&gl=in
==================
Using trie, search complexities can be brought to optimal limit (key length). If we store keys in binary search tree, a well balanced BST will need time proportional to M * log N, where M is maximum string length and N is number of keys in tree. Using trie, we can search the key in O(M) time. However the penalty is on trie storage requirements.

Comment hidden because of low score. Click to expand.
0

With trie, duplicates can be removed efficiently but order will not be maintained in the result.

Comment hidden because of low score. Click to expand.
0
of 0 vote

use hashset as it does't allow duplicates..time complexity to add elements would be O(n).

Comment hidden because of low score. Click to expand.
0

Yes, HashSet works on hashing technique. It finds the hash of the string and choose the appropriate bucket.
Finding hash of the string the Time complexity : O(w), w -- length of the string
So total time is O(n*w).
If I am wrong let me know.
Thank you.

Comment hidden because of low score. Click to expand.
0
of 0 vote

Python=>
list =[“Ted”, “John”, “Mark”, “Ted”, “David”]
dict={}
while i in list:
dict[i]=1
del list
while i in dict.keys:
list+=i

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````'''Python3.3:
Removing duplicates on the fly
E.g.:
a
v
a

a, v
'''

if __name__ == "__main__":
name_space = {}
ordered_list = []
while True:
_name = input("")
if(_name == ""): break

if _name not in name_space:
name_space[_name] = 1
ordered_list.append(_name)

print(list(name_space.keys()))
print("ordered list: ", ordered_list)``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

Here is my solution in C++:

``````void unique_stream(vector<string> &stream)
{
unordered_map<string, int> strMap;
vector<string> vecResult;
for(auto& str: stream)
{
strMap.find(str) != strMap.end() ? ++strMap[str] : strMap[str] = 1 ;
}
for(auto& str: stream)
{
if(strMap[str] == 1)
vecResult.push_back(str);
}
stream = vecResult;
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

List<String> lstStr = new ArrayList<String>();

for(int i=0; i< lstStr.size(); i++)
{
for(int j=1;j<lstStr.size();j++)
{
if(i!= j && lstStr.get(i) == lstStr.get(j))
{
lstStr.remove(j);
j--;
}
if(j>=lstStr.size())
break;
}
if(i>=lstStr.size())
break;
}
for(int k = 0; k<lstStr.size();k++)
{
System.out.println(lstStr.get(k))
}

Comment hidden because of low score. Click to expand.
-1
of 1 vote

Here is the pseudo code-

String[]={"ted","mark","mark",,"ted"}
String pre=s[0];
for(int i=1;i<s.len;i++)
{
if(pre!=s(i))
pre=s(i);
}
return list;

O(n)

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

### Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

### Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.