Amazon Interview Question for Software Engineer / Developers


Team: AWS
Country: United States
Interview Type: Phone Interview




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

How do we get the 1 GB string as an input parameter to the function? The only reasonable explanation would be to store them in Disk as files. Also since we are dealing with files of very large magnitude we dont want to clog the memory with this process. So I would go with a linked list of File pointers that contains a list of files in the sequence as the string. When inserting a new string in middle of old string. split the old string and write them to a file and update the file pointers appropriately.

- Anonymous March 31, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I really don't know the answer. But my guess would to break the Large string into smaller strings and store them in linkedlists. Appending is simple as we can just change the pointer's value.

- Vijay March 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

How would breaking up the large string help you at all? If anything you should break up the small string, since that's what the specification requires.

- eugene.yarovoi March 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think what he meant was use linked lists which store
dynamically allocated character arrays. Each node holds
a character pointer and size of array.
Inserting in position i would be:
1. Mark size=i in first node.
2. Allocate node with pointer=input_string and size=strlen(input_string)
3. Allocate node with pointer=head->pointer+i and size
head_size-i

Concatenation is trivial i.e. head->next=target

- Blahfoo March 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

a linked list of (char*)

- pdgetrf March 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

use trie data structure

- abhi March 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

What advantage will you have if trie's used?

- Vijay March 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Better insert small string in the larger one.first part before the larger string and second part at the last.

- neel March 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Then what about the second part where both are large?

- Vijay March 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

the question is more about memory, so you need to break the string in smaller part. Specially at index point and taking memory constraint in mind and then you can merge all the parts.

- neel March 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

There is Rope data structure which works with large string and supports basic operations with logarithmic complexity.

- V.Krestyannikov May 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

It seems like an ArrayList would work well in both places. ArrayLists are inefficient at inserting small strings into arbitrary positions since the complexity depends on the size of the string already there + the size of the string being inserted. But from this problem statement, the size of the string already there will probably be smaller than the string being inserted, so the complexity will be close to that of simply copying the giant string being inserted. Since copying the giant string is a required part of any solution, this algo compares well with any other algorithm one could devise.

Appending is pretty much always efficient with an ArrayList, so the second case works too.

- eugene.yarovoi March 30, 2012 | 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