You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: leetcode/binary-search/719-find-k-th-smallest-pair-distance.md
+31-2Lines changed: 31 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ Here are all the pairs:
19
19
Then the 1st smallest distance pair is (1,1), and its distance is 0.
20
20
```
21
21
22
-
**Note:
22
+
**Note:
23
23
**
24
24
25
25
1. 2 <= len\(nums\)<= 10000.
@@ -41,9 +41,11 @@ Then the 1st smallest distance pair is (1,1), and its distance is 0.
41
41
5. Space complexity O\(n\)
42
42
3. Binary Search
43
43
1. Since all numbers are non-negative, the kth distance must be in between \[0, max - min\], lo and hi respectively
44
-
2. We perform binary search on this range until lo and hi merge, and we narrow our search using a separate function count\(mi\), where count\(mi\) return numbers of distances smaller than or equal to mi
44
+
2. We perform binary search on this range until lo and hi merge, and we narrow our search using a separate function count\(nums, mi\), where count\(nums, mi\) return numbers of distances <= mi
45
45
3. If count\(mi\) is smaller than k, we have to set lo = mi + 1
46
46
4. Else hi = mi
47
+
5. The count\(nums, mi\) can be efficiently implemented using two pointers \(sliding window\) method
48
+
6. Time complexity O\(nlogn + n^2logw\), where w = max - min
0 commit comments