[Problem link][1]
/* 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
{
// your code goes here
Scanner scr = new Scanner(System.in);
int t,l,hl=0,vl=0;
t = Integer.parseInt(scr.nextLine().trim());
while(t-->0)
{
hl = vl = 0;
l = Integer.parseInt(scr.nextLine().trim());
String line1 = scr.nextLine().trim();
line1 = line1.substring(0,l);
String line2 = scr.nextLine().trim();
line2 = line2.substring(0,l);
if(line1.indexOf('*')>-1&&line2.indexOf('*')>-1)
hl=1;
if(hl==0)
{
for(int i=0;i<l;++i)
{
if(line1.charAt(i)=='*'||line2.charAt(i)=='*')
++vl;
}
--vl;
}
else
{
int l1c=0,l2c=0;
for(int j=0;j<l;++j)
{
if(line1.charAt(j)=='*')
++l1c;
if(line2.charAt(j)=='*')
++l2c;
vl = Math.max(l1c,l2c);
}
--vl;
}
//System.out.println("hl = "+hl+" vl = "+vl);
System.out.println(hl+vl);
}
}
}
Thanks in advance.
[1]: https://www.codechef.com/SNCKPB17/problems/SNCOUP