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.

- truecool June 02, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- aks June 12, 2014 | Flag
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).

- amish.cusat June 01, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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.

- Srinivas June 02, 2014 | Flag
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

- Anonymous June 04, 2014 | Flag Reply
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 

then answer: 
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)

- redM0nk June 22, 2014 | Flag Reply
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;
}

- soby June 29, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

List<String> lstStr = new ArrayList<String>();
lstStr.add("Nuno");
lstStr.add("Paulo");
lstStr.add("Carlos");
lstStr.add("Ana");
lstStr.add("Nuno");
lstStr.add("Paulo");
lstStr.add("Nuno");
lstStr.add("Paulo");
lstStr.add("Sofia");
lstStr.add("Sofia");
lstStr.add("Sofia");
lstStr.add("Sofia");
lstStr.add("Rita");

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))
}

- ngrilo December 30, 2014 | Flag Reply
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];
list.add(pre);
for(int i=1;i<s.len;i++)
{
if(pre!=s(i))
list.add(s(1));
pre=s(i);
}
return list;

O(n)

- yash.varshney05 June 02, 2014 | Flag Reply


Add a Comment
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.

Learn More

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.

Learn More

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.

Learn More

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.

Learn More