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
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 :
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.
@shruti so using qucik sort it will O(nlogn) but question say for O(logn)
Post a Comment