Piyush and Magical Park 2 testcase failed

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int m = scan.nextInt();
int k = scan.nextInt();
int s = scan.nextInt();
//array
char[][] park = new char[n][m];
for(int i =0;i<n;i++){
for(int j=0; j<m;j++){
park[i][j] = scan.next().charAt(0);
}

    }
    boolean flag = true;
    for(int i = 0;i<n;i++){
        flag = true;
        for(int j=0;j<m;j++)
        {
            s=s-1;
            if(park[i][j]=='*')
            {
                
                s=s+5;
            }else if(park[i][j]=='.'){
                
                s=s-2;
            }else{
                flag = false;
                break;
            }
        
        }
        if(flag==true){
            
            break;
        }
    }
    if(flag==true && s>=k){
           System.out.println("Yes");
           System.out.println(s);
        }else{
            System.out.println("No");
        }

}

}

can you please check the logic

Hi Vaibhav,
See the value of s does not decrease by 1 when column is last column i.e. j = m - 1. Also if park[i][j] equals to ‘#’ you just need to break the loop not making the value of flag false. Also suppose if in first row the value of flag remains true but in second row the value of s become less than k then you have print no but your code will print yes.

So i have to traverse all the rows one by one.

Hi Vaibhav,
In your code you are traversing row one by one

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.