link to the code https://ide.codingblocks.com/s/258274
Code not passing test case 2 and 3
your logic is wrong .
your code gives wrong answer for custom input
- 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,
-
if character is β*β, add 5 to the strength.
-
else if, character is β.β , subtract 2 from the strength.
-
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.
Read carefully this line : His strength should always be greater than K while traversing or else Piyush will get lost. Assume that Piyush can shift immediately from last of one row to the start of next one without loss of any strength,
can you tell me for which input my code fails
try for custom input
i did and it works fine
ur code gives
Yes
16
but correct output is
Yes
13
how to input char values in 2 array
@jatin111
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(), m = sc.nextInt(), k = sc.nextInt(), s = sc.nextInt();
char park[][] = new char[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
park[i][j] = sc.next().charAt(0);
}
}
}
i tried your approach but it is giving tle in test case 2 and 3 link to my code https://ide.codingblocks.com/s/258556
@jatin111 just one changes in inner for loop j++
for (int j = 0; j < a[i].length; j++) {
if ( j==0 || (i==n-1 && j==m-1)) {
i dont know how i am doing such silly mistakes