Goldman Sachs Interview Question
636 Interview Reviews |
Back to all Goldman Sachs Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Senior Software Engineer at Goldman Sachs:
How do you find 2 missing elements in an array of consecutive integers that are not sorted who's size is N-2.
See more for this Goldman Sachs Senior Software Engineer Interview
Helpful Question?
Yes |
No
Inappropriate?
Answers & Comments (4)
You can sort the array, but if you don't want modify the user's array, you'll need to make a copy...which depending on the size of the array, might be expensive.
An alternative that I thought of would be to create a bitmap for each element (initializing all bits to 1). Then pass through the vector once and set the corresponding bit 0. After one pass through, you can make a second pass to determine which "sectors" still contain set bits and can extrapolate the missing value accordingly.
Worst case O(2N)
A strategy might be to impose one of the two methods, depending on the size of the array, but sorting inevitably has a floor of O(N), unless you're going to take a probabilistic guess and skip over elements you think might already be sorted. Most algorithms are O(n log n) because the need to visit every element, and the revisiting of some elements to perform the proper placement.
Helpful Answer?
Yes |
No
Inappropriate?
sum of numbers and sum of squares
Helpful Answer?
Yes |
No
Inappropriate?
To comment on this
question,
Sign In with Facebook or
Sign Up



0 of 0 people found this helpful
by Alchemist: