The input specifies there is 1 test case.
For the first test case, the size of the array is 6. The array elements are 5 6 1 2 3 4. We use the arrayRotateCheck function to find the rotation index. Iteration 1: 5 > 6 (not true) Iteration 2: 6 > 1 (true) The current index (i) is 1, and i + 1 is 2. So, the rotation index is 2. The function returns 2. The output for the test case is 2.public class Solution {
public static int arrayRotateCheck(int[] arr){
for(int i = 0 ; i < arr.length-1;i++){
if(arr[i] > arr[i+1]){
return i+1;
}
}
return 0;
// The input specifies there is 1 test case.
// For the first test case, the size of the array is 6.
// The array elements are 5 6 1 2 3 4.
// We use the arrayRotateCheck function to find the rotation index.
// Iteration 1: 5 > 6 (not true)
// Iteration 2: 6 > 1 (true)
// The current index (i) is 1, and i + 1 is 2.
// So, the rotation index is 2.
// The function returns 2.
// The output for the test case is 2.
}
}
Comments
Post a Comment