you give 0indexed 2d array grid size 2 x n gridrc represent number point position r c matrix two robot playing game matrixBoth robot initially start 0 0 want reach 1 n1 each robot right r c r c 1 r c r 1 cAt start game robot move 0 0 1 n1 collecting point cell path for cell r c traverse path gridrc set 0 then second robot move 0 0 1 n1 collecting point path Note path intersect anotherthe robot want minimize number point collect second robot in contrast second robot want maximize number point collect if robot play optimally return number point collect second robot Example 1input grid 254151output 4explanation the optimal path take robot show red optimal path take second robot show blueThe cell visit robot set 0the second robot collect 0 0 4 0 4 pointsExample 2input grid 331852output 4explanation the optimal path take robot show red optimal path take second robot show blueThe cell visit robot set 0the second robot collect 0 3 1 0 4 pointsExample 3input grid 131151331output 7explanation the optimal path take robot show red optimal path take second robot show blueThe cell visit robot set 0the second robot collect 0 1 3 3 0 7 point constraintsgridlength 2n gridrlength1 n 5 1041 gridrc 105