Method
lower_bound
(long arr[], long N, long X)
Source from the content-addressed store, hash-verified
| 17 | //If number of elements greater than root are even then output will be POSITIVE |
| 18 | //If anyone element is equal to root output will be zero |
| 19 | public static long lower_bound(long arr[], long N, long X) |
| 20 | { |
| 21 | long mid; |
| 22 | long low = 0; |
| 23 | long high = N; |
| 24 | while (low < high) |
| 25 | { |
| 26 | mid = low + (high - low) / 2; |
| 27 | if (X <= arr[(int)mid]) |
| 28 | high = mid; |
| 29 | else |
| 30 | low = mid + 1; |
| 31 | } |
| 32 | if(low < N && arr[(int)low] < X) { |
| 33 | low++; |
| 34 | } |
| 35 | return low; |
| 36 | } |
| 37 | //Main function |
| 38 | public static void main (String[] args) throws java.lang.Exception |
| 39 | { |
Tested by
no test coverage detected