Goldman Sachs Interview Question for Software Engineer / Developers

Country: United States

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

lem me add few things..

List is an ordered sequence of elements whereas Set is a distinct list of elements which is unordered
List<E>: -
An ordered collection (also known as a sequence). The user of this interface has precise control over where in the list each element is inserted. The user can access elements by their integer index (position in the list), and search for elements in the list.

A collection that contains no duplicate elements. More formally, sets contain no pair of elements e1 and e2 such that e1.equals(e2), and at most one null element. As implied by its name, this interface models the mathematical set abstraction.

║ ║ List ║ Set ║
║ Duplicates ║ YES ║ NO ║
║ Positional Access ║ YES ║ NO ║

Regarding inserting elements :-
This class implements the Set interface, backed by a hash table (actually a HashMap instance). It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time. This class permits the null element.

The insertion order directly influences the iteration order whenever you have a bucket collision:

When two elements end up in the same bucket, the first one that was inserted will also be the first one returned during iteration, at least if the implementation of collision handling and iteration is straightforward (and the one in Sun's java.util.HashMap is)

- saxenasaral August 18, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

Collection has list,set,map, sortedMap, also vector, hashtable Enumeration which are deprecated

List by contract allows duplicate on the other then set override duplicate entry.

when we are going from List to set we do not store duplicate entries of the object in list. We will basically override the same entry. Going backwards we donot care as list can hold all the objects from set.

HashSet doesnot guarantees the iterator order. Its internal implementation uses HashMap and when you call iterator it iterates over its keyset and gives your the result.

- Prince August 12, 2014 | Flag Reply

Add a Comment

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.


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


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