JP Morgan Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

Both are similar, though slightly different in terms of goal and implementation. In a LinkedList, each element is linked to its previous and next element making it easier to delete or insert in the middle of the list. A ArrayList is more as its name subjects used as an array.
Performance is similar, though LinkedList is optimized when inserting elements before the end of the list, where ArrayList is optimized when adding elements at the end.

- TechTycoon February 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

There are very big differences between a linked list and array list. As you said in a linked list every element or Node is linked together. The advantage is that to add an element to the list, lets say the beginning, has a run time of O(1). In an array list, you would need to move every element back a position, thus O(n). Array list has quicker access time O(1), while linkedlist is O(n).

- Nicolas February 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

ArrayList internally uses an array whereas Linkedlist uses a chain of nodes. So, ArrayList are faster for random search whereas LinkedList are more suitable for insert/delete as we only need to update the nodes in the LinkedList. Searching is slow in LinkedList as we need to do a sequential scan of all the nodes. Arraylist can use the get method for quick random access. Arraylist for insertion is good only when it is inserted at the end of the list. For inserting at the beginning or anywhere in the middle, all the relevant position of elements from the insertion point, needs to be shifted.

to sum it up, adding and deleting at the start and middle of the ArrayList is slow, because all the later elements have to be copied forward or backward. Linked lists are faster for inserts and deletes anywhere in the list, since all you do is update a few next and previous pointers of a node.

- Kumar Keswani February 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

A LinkedList is ordered by index position, like ArrayList, except
that the elements are doubly-linked to one another. This linkage gives you new
methods (beyond what you get from the List interface) for adding and removing
from the beginning or end, which makes it an easy choice for implementing a stack
or queue. Keep in mind that a LinkedList may iterate more slowly than an ArrayList,
but it's a good choice when you need fast insertion and deletion. As of Java 5, the
LinkedList class has been enhanced to implement the java.util.Queue interface. As
such, it now supports the common queue methods: peek(), poll(), and offer().

- VJ May 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

ArrayList allows for O(1) lookup time since its accessible via index just like arrays. Linkedlist requires you to traverse through the list to find the element so O(n) lookup time. ArrayLists are basically arrays that automatically resize. Resizing is expensive so typically an optimized solution is to double to the size as soon as the array gets full. Deletion is faster in Linkedlists though since unlike ArrayLists, you're not using contiguous memory.

- NS February 16, 2016 | 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