Given an integer array nums, take any nums[i] to earn nums[i] points, but delete every element equal to nums[i]-1 and nums[i]+1. Find maximum points you can earn.
Convert to "house robber" problem. Sum all values of each number into points[]. Then find max points from this 1D array (cannot take adjacent values).
- Build points[] where points[i] = i * count(i in nums).
- Find max(points[i-1], points[i-2] + points[i]) from index 2 onward.
- This is identical to the House Robber problem.
- Time Complexity: O(N + max(nums))
- Space Complexity: O(max(nums))