How to check 2d array is completely traversed or not
Hello @Imsbajetha,
-
If you are asking this question in general sense, then the answer is:
After the complete traversal, the value of i and j will be r(row) and c(column) -
With respect to the question, it is not necessary to traverse all the cells of the matrix or park:
You have to take the following points under consideration while solving this question:
2.1. Initially, the strength is S
2.2. if Piyush encounters *, strength increases by 5
2.3. If he encounters β.β, strength decreases by 2
2.4. Piyush requires strength of 1 for every step
2.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)
2.6. If he changes the row after encountering the β#β, then he loses 1 strength for changing the row.
2.7. he needs at least a K amount of strength to reach home.
Letβs understand the sample Testcase given in the question:
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
Check if your code satisfies above mentioned 7 points, especially point 2.4 and 2.6.
Hope, this would help.
Give a like if you are satisfied.