The Number of Beautiful Subsets

You are given an array nums of positive integers and a positive integer k.

A subset of nums is beautiful if it does not contain two integers with an absolute difference equal to k.

Return the number of non-empty beautiful subsets of the array nums.

A subset of nums is an array that can be obtained by deleting some (possibly none) elements from nums. Two subsets are different if and only if the chosen indices to delete are different.

Example 1
Inputnums = [2,4,6], k = 2
Output4
The beautiful subsets of nums are [2], [4], [6], and [2, 6], so there are only 4 beautiful subsets.
Example 2
Inputnums = [1], k = 1
Output1
The beautiful subset of nums is [1], so there is only 1 beautiful subset.

Constraints

  • 1 <= nums.length <= 18
  • 1 <= nums[i], k <= 1000

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate