Microsoft/Phonepe Interview question

Anonymous User
1198
Jun 01, 2022

Enocunterd this question recently in PS/DS rounds of two companies :

Given a N by M matrix, find the maxium sum possible if we have to choose one element from each row. For example if matrix has N rows then this sum will be formed by N elements from each row. The only constraint is if we have picked an element from the ith row, then we cannot choose element from the same column in (i-1)th and (i+1)th row [if exist].

Example :
1,2,3
4,5,6
7,8,9

Maxium sum is : 3 + 5+ 9
Note that matrix elements can be random, not sorted as shown in example.

Comments (9)