sushantsangwan2006's blog

By sushantsangwan2006, history, 43 hours ago, In English

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..

»
42 hours ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Ball can be placed at any cell (i,j) If previous cells of enrire row i OR previous cells of entire column is filled.

  • »
    »
    42 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    i don't understand can you please elaborate..

    • »
      »
      »
      41 hour(s) ago, # ^ |
        Vote: I like it +3 Vote: I do not like it
      1010
      0000
      1110
      0010
      

      Try Understanding this case you will get your answer.

      • »
        »
        »
        »
        40 hours ago, # ^ |
        Rev. 2   Vote: I like it 0 Vote: I do not like it

        ,,

        • »
          »
          »
          »
          »
          40 hours ago, # ^ |
          Rev. 3   Vote: I like it 0 Vote: I do not like it

          ,,

    • »
      »
      »
      40 hours ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      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.

»
42 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

I did the same thing too :(

»
42 hours ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

.

»
40 hours ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

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.

  • »
    »
    37 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    can you give me a test case which my code fail and explain it from it ,as it will be helpful for me?

    • »
      »
      »
      36 hours ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      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.

  • »
    »
    37 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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??