MCPcopy Index your code
hub / github.com/careercup/ctci / validate

Method validate

java/Chapter 17/Question17_6/Question.java:82–97  ·  view source on GitHub ↗
(int[] array, int left_index, int right_index)

Source from the content-addressed store, hash-verified

80 * validation, as it does not check if these are the best possible indices.
81 */
82 public static boolean validate(int[] array, int left_index, int right_index) {
83 int[] middle = new int[right_index - left_index + 1];
84 for (int i = left_index; i <= right_index; i++) {
85 middle[i - left_index] = array[i];
86 }
87 java.util.Arrays.sort(middle);
88 for (int i = left_index; i <= right_index; i++) {
89 array[i] = middle[i - left_index];
90 }
91 for (int i = 1; i < array.length; i++) {
92 if (array[i-1] > array[i]) {
93 return false;
94 }
95 }
96 return true;
97 }
98
99 public static void main(String[] args) {
100 int[] array = {1, 2, 4, 7, 10, 11, 8, 12, 5, 7, 16, 18, 19};

Callers 1

findUnsortedSequenceMethod · 0.95

Calls 1

sortMethod · 0.45

Tested by

no test coverage detected