give n x n binary grid step choose adjacent row grid swap themA grid say valid cell main diagonal zerosreturn minimum number step need grid valid 1 grid validthe main diagonal grid diagonal start cell 1 1 end cell n n Example 1input grid 001110100output 3example 2input grid 0110011001100110output 1explanation all row similar swap effect gridExample 3input grid 100110111output 0 Constraintsn gridlength gridilength1 n 200gridij 0 1