MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / findCeiling

Method findCeiling

Programs/CeilingFloor.java:5–18  ·  view source on GitHub ↗
(int[] arr, int target)

Source from the content-addressed store, hash-verified

3public class CeilingFloor {
4
5 static int findCeiling(int[] arr, int target) {
6 int start = 0, end = arr.length - 1;
7 while (start <= end) {
8 int mid = start + (end - start) / 2;
9 if (target < arr[mid]) {
10 end = mid - 1;
11 } else if (target > arr[mid]) {
12 start = mid + 1;
13 } else {
14 return arr[mid];
15 }
16 }
17 return arr[start];
18 }
19
20 static int findFloor(int arr[], int target) {
21 int start = 0, end = arr.length - 1;

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected