blob: bb73cd8f486fad2d05b629beec660dc6a746f03e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
def find_ind(key, i, n,
k, arr):
ind = -1
start = i + 1
end = n - 1;
while (start < end):
mid = int(start +
(end - start) / 2)
if (arr[mid] - key <= k):
ind = mid
start = mid + 1
else:
end = mid
return ind
def removals(arr, n, k):
ans = n - 1
arr.sort()
for i in range(0, n):
j = find_ind(arr[i], i,
n, k, arr)
if (j != -1):
ans = min(ans, n -
(j - i + 1))
return ans
|