public static int searchIntervals(int[] nums) {
int sum = 0;
for (int i = 0; i < nums.length - 1; i++) {
if (nums[i] > nums[i + 1]) {
sum++;
if (i + 2 <= nums.length - 1) {
if (nums[i + 1] > nums[i + 2]) {
i++;
}
}
}
}
return sum;
}
private static int searchIntervals(int[] nums) {
int sum = 0;
for (int i = 0; i < nums.length - 1; i++) {
if (nums[i] > nums[i + 1]) {
sum++;
int cntr = 0;
for (int h = i+1; h < nums.length - 1 - i; h++) {
cntr++;
if (nums[h] > nums[h + 1]) continue;
else break;
}
i+=cntr;
}
}
return sum;
}