Skip to content

Commit c9a0510

Browse files
authored
Create Lower Bound of Array Element using Binary Search.py
1 parent 98effb9 commit c9a0510

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def lowerBound(arr: [int], n: int, x: int) -> int:
2+
# Write your code here
3+
low = 0
4+
high = n - 1
5+
while low <= high:
6+
mid = (low + high) // 2
7+
if arr[mid] >= x and mid > 0 and arr[mid - 1] < x:
8+
return mid
9+
if arr[mid] >= x:
10+
high = mid - 1
11+
else:
12+
low = mid + 1
13+
if arr[0] >= x:
14+
return 0
15+
else:
16+
return n

0 commit comments

Comments
 (0)