Please explain the sample output

I viewed the hint video and followed the example.
if char is ‘*’ : S + 4
if char is ’ .’ : S - 3
If S < 5 return No
Else return “Yes” with value of S

4 4 5 20
. . * . At row 0, S : 15
. # . . At row 1, S : 12

    • . . At row 2, S : 14
      . # * * At row 3, S : 11

Hello @Sriram-Rajan-10104264111174086,

You have to take the following points under consideration while solving this question:

  1. Initially the strength is S
  2. if Piyush encounters * , strength increases by 5
  3. If he encounters ‘.’, strength decreases by 2
  4. Piyush requires strength of 1 for every step
  5. Piyush can shift immediately from last of one row to the start of next one without loss of any strength(i.e. when he would change the row from the last element of the row)
  6. If he changes the row after encountering the ‘#’, then he looses 1 strength for changing the row.
  7. he needs atleast K amount of strength

Outputn Format:

  1. You have to print, “Yes” if at last he has strength >=K.
    else, print “No”
  2. If the result is “Yes”, then print the strength that he can gather in the park.
    But for, you don’t have to print anything in the second.

Let’s understand the sample Testcase:
4 4 5 20
. . * .
. # . .
* * . .
. # * *
S=20 and k=5;

A. first row:
20-2-1-2-1+5-1-2=16

B. second row:
16-2=14 (Now, he cannot move any further)

C. third row: -1 for changing the row (point 6.)
14-1+5-1+5-1-2-1-2=16

D. fourth Row:
16-2-1=13

As 13 >=5, Print “Yes” and 13

Hope, this would help.
Give a like, if you are satisfied.

1 Like

please review my code at : https://ide.codingblocks.com/s/114409

Failing for 2 testcases

Hello @S18ML0016,

I have corrected all the mistakes in your code:

I have written the necessary comments for better understanding.
Let me know if you still face issue.

Give a like, if you are satisfied.