Wednesday, January 25, 2012

Google Wants Us to Find an Element thats greater then A, in Unsorted Element....Do You Think its Possible or Just They Wants to Test if Possible or Not

First greater number in an array. Given a large array of positive
integers, for an arbitrary integer A, we want to know the first integer in
the array which is greater than or equal A . O(logn) solution required
ex [2, 10,5,6,80]


input : 6 output : 10
input :20 output : 80

2 comments :

Anonymous said...

How about using quick sort in this case with 7 as the pivot.

In case it is a number which doesnot exist in the array , lets insert that element in the middle of the array and then do a quick sort.

In both the cases, after the sorting is completed, the element immediately after the pivot will be our required answer.

Shruti.

Unknown said...

@shruti so using qucik sort it will O(nlogn) but question say for O(logn)