grid and a step step. One move adds step to any single cell or subtracts it from that cell.
Return the fewest moves after which all cells hold the same value, or -1 if that is impossible.grid=[[3, 9], [6, 12]], step=3 → 4
Level everything to 6: raise 3 by one step, lower 9 by one step and 12 by two. That is 4 moves.
grid=[[5, 7, 8]], step=2 → -1
5 and 7 are odd while 8 is even, so steps of 2 can never make them equal.
grid=[[4], [4]], step=7 → 0
The cells are already equal.
grid=[[3, 9], [6, 12]], step=3
4
Run checks the first 3 tests in your browser. Submit checks all 98 tests on the server, hidden ones included.