Amazon Interview Question for SDE1s


Country: India
Interview Type: In-Person




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

I assume by infinitely large you mean an array that does not fit in memory otherwise your program will never terminate obviously. If that's the case this sounds like a simple problem
* Create k files (k - number of tags)
* Read the input array by blocks that fit in memory
* If an element in the block has tag i add it to i-th file
* When you are done processing the array, just traverse your files in order

- adr June 10, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Let left =0 and right =arr.length()-1;
traverse the array and do
//move left pointer from left to right.

if(arr[left].tag==1){
	//move the right pointer(from right to left) until a tag 0 is encountered
	//and swap the values at left and right.
}

- Anonymous June 12, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think
An array can't have infinite size as it have maximum size of integer

- Rishi June 12, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Initialize a hash table for with tag as key and ArrayList of elements as value.
2. loop through the array int[] a; if the tag doesn't exist add the tag and add a[i] to its ArrayList; if the tag already exists in the hash table, add a[i] to the ArrayList.
3. After the loop is done, now loop through the Hash Table and print all the tags and its ArrayList contents in the order.

- Varun Erra June 19, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Start reading the elements one by one, insert tag 0 elements from the begining of the array and tag 1 from the end. This sort can be perform in-place to receive the best memory and space performance.

- Nooreddin June 20, 2018 | 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