Given an array whose elements are sorted, return the index of a the first occurrence of a specific integer. Do this in sub-linear time. I.e. do not just go through each element searching for that element.
Anonymous
To respond to Sid's comment: Binary search is the way to go, but you do need a slight modification, coz a simple binary search may not necessarily return the index of the first occurence, e.g. given input array 7777777777, what would a simple search return? The trick would be to seek to the left if the index at the middle of the current partition is the element you are looking for. The performance would depend on how many duplicates there are on average + log n If this average is n as in the above example you are looking at O(n/2), but then if you knew that already you could simply return the first element :) Anyone have a better idea?
Check out your Company Bowl for anonymous work chats.