Goldman Sachs Interview Question for Analysts

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

List
-Searching O(n)
-Inserting, deleting, moving O(1)
-Elements may be ordered. (order from which they are added)
-Elements may be sorted.
-Elements may be duplicate.

Set
-Searching (logarithmic in size).
-Insert and delete (logarithimic in general).
-Elements are un-ordered. (they are sorted on insert, doesn't keep the order it was inserted)
-Elements are always sorted from lower to higher.
-Elements are unique.

a set is always sorted, a list can be sorted on insert too depend on setting.
a set is kind of a subgroup of a list with more restriction but better performance.
Just remember that values are unique.
As far as I know a set is sorted, but I'm sure this is a debatable subject, might be some people that created set object/list that aren't sorted on insert... but as far as I know, a set is suppose to sort value on insert...

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

In addition, set contains data in sorted order whereas list does not.

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

@rajendra: (5,4,2,1,3) is also a set but not sorted.... Set is just a collection of distinct elements..

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

also @rajendra: list generally preserves order while set does not guarantee it.

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

Set doesn't maintain Order of insertion but List does.

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

List is implemented as doubly link List. so we can push element at the back and front . similarly we can also pop element from back and front . complexity for push and pop is O(1).

Sets are containers which store only unique values . The values in the sets are stored in some specific order (like ascending or descending). compexity for inserting and searching any value is O(logN) .

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

Set does not allow duplicates and list allows duplicates

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.

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.