I got the following question for the OA from Quora.
Given a multiset of integers, find the max number we can get as the sum of a sub-multiset of these integers such that no 2 integers have an absolute difference of 1
Example:
If the multiset is [1,1,2,3,3,3,4,4,5,5,5,15],
the max sum is (1+1+3+3+3+5+5+5 = 26)
If the multiset is [3,3,4,4,4,5,5,5,5,6,6,10,20],
the max sum is (3+3+5+5+5+5+10+20 = 56)This is similar to another question on LC relating to finding the subset with maximum sum such that no two elements are adjacent to each other. For that particular question, I used a dynamic programming approach and tried to use that same approach to try to solve this question, but wasn't successful. Woud still like to learn how to solve this particular question so any guidance would be much appreciated.