You hold a pile of numbered cards cards. A move is: choose a card with value v, score v points, then discard that card and every card whose value is v - 1 or v + 1 (other cards with value v stay and can be scored later). Repeat until the pile is empty. Return the maximum score.
Examples
Input: cards = [5, 6, 8]
Output: 14
Explanation: score the 6 (discarding the 5), then score the 8.
Input: cards = [3, 3, 3, 4, 4, 5, 5]
Output: 19
Explanation: scoring the three 3s (9 points) and the two 5s (10 points) discards both 4s.
Constraints
1 <= len(cards) <= 10**51 <= cards[i] <= 10**5- Target complexity: O(n + max(cards)) or O(n log n) time.
Goals
- Transform a value-deletion game into a take-or-skip problem over sorted values
- Aggregate duplicates before running the recurrence