Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

If you frequently add elements to the beginning of the List or iterate over the List to delete elements from its interior, you should consider using LinkedList. These operations require constant-time in a LinkedList and linear-time in an ArrayList. But you pay a big price in performance. Positional access requires linear-time in a LinkedList and constant-time in an ArrayList.

- llval April 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

"If you frequently add elements to the beginning of the List or iterate over the List to delete elements from its interior, you should consider using LinkedList. These operations require constant-time in a LinkedList and linear-time in an ArrayList. But you pay a big price in performance. Positional access requires linear-time in a LinkedList and constant-time in an ArrayList."

- llval April 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The question pertained to collection framework , you can put an object in the middle by specifying index in Linkedlist.
What answer I gave to him was is that when you add an element to an array outside its bound. The arraylist expands by 50% but here the problem is for one element you expand by 50% which is not required by LinkedList.

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

ArrayList implements the Random Access Interface, which means u can access an element like an array by using its index. LinkedList implementation in collections helps you to specify the location index as well, but it uses the head or tail pointer to traverse to that node, based on whichever is close by.

Random Resizing is another feature of arrayList which can be done to ensureCapacity() for incoming elements. No such specs in linkedList.

LinkedList takes lesser space as it never stores null nodes, ArrayLists might be augmented or decremented by a constant value which might occupy more space.

- Sindhuja April 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Another point to the previous answer is, if the arrayList increases the specified capacity, the contents need to be copied internally to a newer bigger array as arrayList uses an array for the internal implmentation. Thats not the case with linkedlist. Copying overhead can be avoided.

- Sindhuja April 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

vfdv

- Anonymous January 04, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Array:
In array we cannot add or delete an element, except that we can add at the end
Arrays have fixed length
Finding an element takes O(1) time

LinkedList:
In LinkedList an element can be added at any place after creation at any time
Insertion and deletion takes O(1) or constant time
There is no particular size in linked list, so any number of elements can be added until memory runs out
Finding an element takes O(n) times

- Rajmohan Loganathan January 04, 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