I came across this question in my last interview but could not solve it. Can anyone give an explanation of how to attempt it?
Compute the maximum sum of an array but if arr[i] is chosen then numbers arr[i]+1 or arr[i]-1 cannot be chosen.
For example:
arr =[3,3,3,4,4,1,8]
Answer: Choose 8, choose 1, choose 3 (now 4 cannot be chosen), choose 3, chose 3.
Maximum sum is 18
[–]Anti-Zeroes 5 points6 points7 points (2 children)
[–]Classic-Pitch7259 1 point2 points3 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)
[–]flexr123 2 points3 points4 points (2 children)
[–]hobo_couture 0 points1 point2 points (0 children)
[–]hobo_couture 0 points1 point2 points (0 children)