MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / select

Method select

java/0347-top-k-frequent-elements.java:51–65  ·  view source on GitHub ↗
(
        int[] keys,
        Map<Integer, Integer> map,
        int left,
        int right,
        int kSmallest
    )

Source from the content-addressed store, hash-verified

49 // Modified implementation of Hoare's selection algorithm:
50
51 private void select(
52 int[] keys,
53 Map<Integer, Integer> map,
54 int left,
55 int right,
56 int kSmallest
57 ) {
58 while (left != right) {
59 int pivot = partition(keys, map, left, right, (left + right) / 2);
60
61 if (kSmallest == pivot) return;
62
63 if (kSmallest < pivot) right = pivot - 1; else left = pivot + 1;
64 }
65 }
66
67 private int partition(
68 int[] keys,

Callers 1

topKFrequentMethod · 0.95

Calls 1

partitionMethod · 0.95

Tested by

no test coverage detected