Perfect subarray
Time Limit: 2.0 s
Memory Limit: 256.0 MB
Description
A subarray is called perfect if it
- starts with 1
- ends with 3
- do not contain 2
Alice has an array of length \(N\). He wants to find the longest subarray from his array that is perfect.
Can you help alice in this task ?
A subarray is a contigious part of the array. for example {1} {2} {3} {1,2} {2,3} {1,2,3} each are the valid subarrays of the array {1,2,3) while {1,3} is not a valid subarray.
Input
First line takes in an integer \(T\) : number of testcases
in each testcase
first line takes an integer \(N\) : size of the array
second line takes \(N\) integers : the elements of the array
1 <= \(T\) <= 100
1 <= \(N\) <= 100000
1 <= \(Ai\) <= 10
sum of N over all testcase will not exceed 10^5
Output
print \(T\) integer in each line : the maximum length of a perfect subarray
Sample
Input | Output |
---|---|
|
|
in testcase 1, the longest perfect subarray is {1 8 3}
the subarray {1,1,2,5,3} is not valid because it contains 2
in testcase 2 , the longest perfect subarray is 1 1 3 3
Information
- ID
- 1036
- Difficulty
- 5
- Category
- Beginners Click to Show
- Tags
- (None)
- # Submissions
- 23
- Accepted
- 12
- Accepted Ratio
- 52%
- Uploaded By
Related
In following contests: