-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoodSubsequence.java
More file actions
35 lines (32 loc) · 948 Bytes
/
GoodSubsequence.java
File metadata and controls
35 lines (32 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.Scanner;
import java.lang.*;
import java.io.*;
class Codechef {
public static void main(String[] args) throws java.lang.Exception {
// your code goes here
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while (T-- > 0) {
int N = sc.nextInt();
if (N == 0) {
System.out.println(0);
continue;
}
int A[] = new int[N];
for (int i = 0; i < N; i++) {
A[i] = sc.nextInt();
}
int length = 1;
int lastParity = A[0] % 2;
for (int i = 1; i < N; i++) {
int currentParity = A[i] % 2;
if (currentParity != lastParity) {
length++;
lastParity = currentParity;
}
}
System.out.println(length);
}
sc.close();
}
}