Microsoft/Phonepe Interview question

Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2022-06-01Added By Anonymous
Source: Link
🧭 Experience: unknown
✅ Outcome: unknown
💰 Compensation: unknown
📍 Location: unknown
🏢 Company: PhonePe
🎓 Education: unknown
🎁 Benefits: unknown
📅 Offer Date: unknown

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 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

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