312026676 why this code fail on test case number 3 my approach — I assume that if in final grid there exist a ball i.e v[i][j] == 1 but (v[i-1][j] != 1 && v[i][j-1] != 1 )(except i ==0 || j ==0 (0 based index)). then the answer is false otherwise true..
Ball can be placed at any cell (i,j) If previous cells of enrire row i OR previous cells of entire column is filled.
i don't understand can you please elaborate..
Try Understanding this case you will get your answer.
,,
,,
Think 1 as a block and 0 as a empty space, You can only put a block on leftmost edge of a particular row or the topmost edge of a particular column (attention: You can only push one step), Then if there is Block at (i,j) There must be a series of block in i row or jth column that have pushed this block.
I did the same thing too :(
.
What you're doing is,if there is a ball you're checking only previous row and previous columns' cells. But two consecutive row or two consecutive column cell doesn't guarantee the possibility of final scenario. Because whenever a new ball is pushed,it always gets placed at the previous cell of previously pushed ball. So either row wise or column wise,the balls need to be placed consecutively(from the first row or from the first column). Suppose one takes first cell and another one takes 3rd cell row wise,your code prints "YES" for this but it might be "NO" if column wise the 3rd cell's previous all cells are not occupied.
can you give me a test case which my code fail and explain it from it ,as it will be helpful for me?
Try this: 1010
0000
1110
0010
Here your code might print "YES" but the answer should be "NO".Your code will print "YES" because what you're doing is for every '1' you're checking if any neighbouring '1' is there or not. According to this test case for every '1' there is a neighbouring '1' considering previous row or previous column so your code is giving "YES". But look at the '1' of (4,3) cell,how did it come here? From the start of the 3rd column? It is not possible because in the 3rd column 2nd row is '0'. From the start of the 4th row? It is neither possible because both 1st and 2nd element of 4th row is '0'. So this (4,3) cell's '1' makes the overall final scenario impossible but your code makes it possible because your code considering (3,3) cell's '1' for the (4,3) cell's '1' but ignoring the fact that (2,3) cell is not '1' rather '0' so 3rd column is not complete from start.
ok thank you very much for this....
I am checking it for all one present in the final state so how can it be wrong? like 000 001 100 it prints "NO" as as one ball cannot be pushed in the third column and second row as either full second row should be 1 or third column and first row should be one.. can you explain it where does my does my code fail and how??