Jump to Sibling Solution | CodeChef Problem Solution 2022
Lav has an array of size . He noticed that Chef is initially standing at the first index of the array.
While standing at the index of the array, Chef can perform the following types of jumps:
- : Jump to the immediate next index such that and have the same parity.
- : Jump to the immediate next index such that and have different parity.
Given that Chef can perform at most once, Lav wants to find the minimum number of jumps required by the Chef to reach the last index of the array.
Input Format
- First line will contain , the number of test cases. Then the test cases follow.
- The first line of each test case contains a single integer - the size of the array .
- The second line of each test case contains integers - the elements of the array .
Output Format
For each test case, output the minimum number of jumps required by the Chef to reach the last index of the array.
Constraints
Sample Input 1
2
4
1 2 3 4
4
2 1 3 4
Sample Output 1
2
1
Explanation
Test Case : The minimum number of jumps required by the Chef to reach the last index is . Chef is initially standing at index .
- Chef chooses and jumps to index as it is the immediate next element with different parity.
- Chef chooses and jumps to index as it is the immediate next element with the same parity.
Test Case : The minimum number of jumps required by the Chef to reach the last index is . Chef is currently standing at index .
- Chef chooses and jumps to index as it is the immediate next element with the same parity.
No comments:
Post a Comment