MCPcopy
hub / github.com/careercup/ctci / rank

Method rank

java/Chapter 18/Question18_6/QuestionC.java:98–109  ·  view source on GitHub ↗
(int[] array, int left, int right, int rank)

Source from the content-addressed store, hash-verified

96 }
97
98 public static int rank(int[] array, int left, int right, int rank) {
99 int pivot = array[randomIntInRange(left, right)];
100 int leftEnd = partition(array, left, right, pivot); // returns end of left partition
101 int leftSize = leftEnd - left + 1;
102 if (leftSize == rank + 1) {
103 return max(array, left, leftEnd);
104 } else if (rank < leftSize) {
105 return rank(array, left, leftEnd, rank);
106 } else {
107 return rank(array, leftEnd + 1, right, rank - leftSize);
108 }
109 }
110
111
112 public static void main(String[] args) {

Callers 1

mainMethod · 0.95

Calls 3

randomIntInRangeMethod · 0.95
partitionMethod · 0.95
maxMethod · 0.95

Tested by

no test coverage detected