Microsoft/Phonepe Interview question

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

Company: Microsoft
Role: SDE
Interview Stage: Phone Screen
Location: unknown
Year: unknown

Original Post Content:

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

Given a N by M matrix, find the maximum sum possible if we have to choose one element from each row. For example, if a 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 an 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

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

Comments