if ‘#’ means blocked then that row is blocked, it means he can never pass that row so answer should be No always because to go on to the next row it should reach the current row’s last position?
am i saying correct?
Piyush and magical park
Hello @sktg99,
Nope, it means he cannot move any further in that particular row.
But, he can move to the next row from there.
In case, if he encounters ‘#’ in the last row, then he would directly exit the park.
You have to take the following points under consideration while solving this question:
- Initially, the strength is S
- if Piyush encounters *, strength increases by 5
- If he encounters ‘.’, strength decreases by 2
- Piyush requires strength of 1 for every step
- 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)
- If he changes the row after encountering the ‘#’, then he loses 1 strength for changing the row.
- he needs at least K amount of strength to reach home.
Output Format:
- You have to print, “Yes” if at last, he has strength >=K.
else, print “No” - 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.