Imagine you're organizing a special art exhibition where certain paintings cannot be displayed together due to their contrasting styles. You have an array nums of positive integers representing different artwork IDs, and a positive integer k representing the "conflict threshold".
A subset of artworks is considered "beautiful" if it doesn't contain any two pieces whose ID numbers have an absolute difference equal to k. For example, if k=3, then artworks with IDs 5 and 8 cannot be in the same beautiful subset since |5-8| = 3.
Your goal is to count all possible non-empty beautiful subsets that can be formed from the given array. Remember, each subset represents a different way to curate your exhibition!
Example: With nums = [2,4,6] and k = 2, the beautiful subsets are: [2], [4], [6], [2,6] (note that [2,4] and [4,6] are not beautiful since their differences equal k=2).
Input & Output
Visualization
Time & Space Complexity
In worst case still explores all subsets, but with early pruning it's much faster in practice
Space for recursion stack and frequency map
Constraints
- 1 โค nums.length โค 20
- 1 โค nums[i], k โค 1000
- All elements in nums are positive integers
- The array may contain duplicate values