## Bloomberg LP Interview Question Financial Software Developers

• 0

How to search a number among a lot of numbers. I asked if it is one time thing. Answer is yes. Then I did sequential search; Then he said how about search another one....
Then I said sort these numbers first and suggest binary tree.
Wrote down the binary search code

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

Maybe they wanted to check what kind of questions to ask given such a simple requirement.

Also, there is a glitch in the implementation of Binary Search, specially when we do
mid = (low + high)/2
If the numbers are really large, the sum of (low + high) would overflow and cycle to a negative number.
One work around is to use
mid = low + (high - low)/2

HTH,
Chander

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

There is a one time cost of O(nlogn) to sort the numbers. But if the search is to be carried out frequently then the cost of each search will be O(n) if the list is not sorted as opposed to O(log n) if the list is sorted

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

sort and binary search

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

Could it be this easy??

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

Why not use a Hash?
Is using external memory a case?
Hash will give you the number at one shot

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

Ajay, What do you mean by 'use a Hash' ? Did you want to hash the numbers in the stream ? Or, use a Hashtable? How does either help you in the case of a very large set of numbers?

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

If you sort and binary search, the time complexity is O(NlogN), which is not better than the linear search O(N). Hence, you can't use sort.

Name:

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

### Books

is a comprehensive book walking you through 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.