The most popular feature on snapchat is Snapchat Streak.
A streak is maintained between two people if both of them send at least one snap to each other daily.
If, on any day, either person forgets to send at least one snap, the streak breaks and the streak count is set to 00.
Chef and Chefina like maintaining their snapchat streak. You observed the snap count of both of them for NN consecutive days.
On the i^{th}ith day, Chef sent A_iAi snaps to Chefina while Chefina sent B_iBi snaps to Chef.
Find the maximum streak count they achieved in those NN days.
Input Format
- The first line of input will contain a single integer TT, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains an integer NN — the number of days you observed.
- The second lines contains NN space-separated integers — A_1, A_2, \ldots, A_NA1,A2,…,AN, the number of snaps Chef sent to Chefina on the i^{th}ith day.
- The third lines contains NN space-separated integers — B_1, B_2, \ldots, B_NB1,B2,…,BN, the number of snaps Chefina sent to Chef on the i^{th}ith day.
Output Format
For each test case, output on a new line, the maximum streak count they achieved in those NN days.
Constraints
Sample 1:
Input
4 3 3 1 2 2 4 1 2 0 0 10 10 4 5 4 0 2 3 1 1 0 5 0 1 1 2 0 1 1 0 0 3
Output
3 0 2 1
Explanation:
Test case 11: For all 33 days, both Chef and Chefina sent at least one snap per day. Thus, at the end of third day, the streak count is 33.
Test case 22: Chef did not send any snap to Chefina. Thus, at the streak count remains 00 on both days.
Test case 33: For the first two days, both Chef and Chefina send at least one snap per day. Thus, at the end of second day, the streak count is 22.
On the end of third day, since Chef did not send any snap, the streak count becomes 00.
On the end of fourth day, since Chefina did not send any snap, the streak count remains 00.
Test case 44:
- On the end of first day, since Chef did not send any snap, the streak count remains 00.
- On second day, both Chef and Chefina sent at least one snap. Thus, the streak count becomes 11.
- On the end of third day, since Chefina did not send any snap, the streak count becomes 00.
- On the end of fourth day, since Chefina did not send any snap, the streak count remains 00.
- On the end of fifth day, since Chef did not send any snap, the streak count remains 00.
The maximum streak count over 55 days is 11.
Solution
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int b = sc.nextInt();
int c1[] = new int[b];
int c2[] = new int[b];
for(int i=0; i<b; i++){
c1[i] = sc.nextInt();
}
for(int i=0; i<b; i++){
c2[i] = sc.nextInt();
}
int d[] = new int[b];
for(int i=0; i<b; i++){
if(c1[i] == 0 || c2[i] == 0){
d[i] = 0;
}
else{
d[i] = 1;
}
}
int i = 0;
int result = 0;
while(i<b){
if(d[i] != 0){
int count = 0;
while(i<b && d[i] != 0){
count++;
// sauravhathi
i++;
}
result = Math.max(result, count);
}
else{
i++;
}
}
System.out.println(result);
}
}
}
Happy Learning – If you require any further information, feel free to contact me.