Microsoft/Phonepe Interview question

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2022-06-01Added By Anonymous
Source: Link

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