you give m x n integer matrix point 0indexed start 0 point want maximize number point matrixto gain point pick cell row picking cell coordinate r c add pointsrc scorehowever lose point pick cell far cell pick previous row for adjacent row r r 1 0 r m 1 picking cell coordinate r c1 r 1 c2 subtract absc1 c2 scorereturn maximum number point achieveabsx define asx x 0x x 0 example 1input point 123151311output 9explanationthe blue cell denote optimal cell pick coordinate 0 2 1 1 2 0you add 3 5 3 11 scorehowever subtract abs2 1 abs1 0 2 scoreyour final score 11 2 9example 2input point 152342output 11explanationthe blue cell denote optimal cell pick coordinate 0 1 1 1 2 0you add 5 3 4 12 scorehowever subtract abs1 1 abs1 0 1 scoreyour final score 12 1 11 Constraintsm pointslengthn pointsrlength1 m n 1051 m n 1050 pointsrc 105