diff options
Diffstat (limited to 'progs/a101.py')
-rw-r--r-- | progs/a101.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/progs/a101.py b/progs/a101.py new file mode 100644 index 0000000..bb73cd8 --- /dev/null +++ b/progs/a101.py @@ -0,0 +1,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
\ No newline at end of file |