Rubrik | Phone Interview | Maximum Sum
Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2020-12-04Added By Anonymous
Source: Link
Given a multiset of integers, find the subset of integers that adds to the maximum sum, such that no two numerically consecutive integers (i.e., n and n+1) are in the subset.
Return the maximum sum.
INPUT: {1, 1, 1, 2, 2, 3, 6}
OUTPUT: 12
EXPLANATION: Take the 1's, 3's, and 6's: 1+1+1+3+6 = 12