String challenge ( piyush and magical park )

sir my three of the test case is getting wrong ,plz clarify…

package chall_Strings;

import java.util.*;

public class piyushAndMagicalPark {
static Scanner s=new Scanner(System.in);
public static void main(String[] args) {
int row=s.nextInt();
int col=s.nextInt();
int min=s.nextInt();
int str=s.nextInt();
char[][] arr=new char[row][col];
for(int i=0 ;i<row ;i++) {
for(int j=0 ;j<col ;j++) {
arr[i][j] =s.next().charAt(0);
}
}
for(int i=0 ;i <row ;i++) {
for(int j=0 ;j <col ;j++) {
char ch=arr[i][j];
if( j == (col -1)) {
if(ch == ‘*’) {
str =str+5;
}else if(ch == ‘.’) {
str =str-2;
}else {
break;
}
}else {

	if(ch == '*'){
		str = str-1;
		str=str + 5;
	}else if( ch == '.') {
str=str-1;
		str = str-2;
	}else {
		
		break;
	}
	}
}

}
if(str > min) {
System.out.print(“Yes”+"\n" +str);
}else {
System.out.print(“No”);
}
}
}

this is my code

@sameeksha,
You will not print “No” in any case.

  • Start from the 0-0 index of the 2 - D matrix( No step would be count hence, strength remain intact).
  • Changing row won’t take any strength.
  • If at any time, the Strength become smaller than K ( threshold for piyush), then no need to traverse rest of the array, you can say no nothing else.

Algorithm

  • Take input N, M, K, S.
  • Take input 2 - D matrix of size N x M.
  • Put a loop on the array starting from 0 - 0 index to (N - 1) - (M - 1).
  • check if the Strength is lower than the threshold viz, K, print “No” and return.
  • otherwise,
    1. if character is ‘*’, add 5 to the strength.

    2. else if, character is ‘.’ , subtract 2 from the strength.

    3. else, if character is ‘#’, break.

  • If you are not in the last column, decrement strength by 1.
  • After the loop, print ‘Yes’ and strength separated by a new line.

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.