Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

The Number of Beautiful Subsets

XPChallenge Points: 20
levelLevel: Medium

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

We call a subset beautiful if no two numbers inside it differ by exactly k.
Your task is to determine how many non-empty beautiful subsets can be formed from nums.

A subset is formed by choosing any combination of elements while keeping their original index distinctions. Two subsets are counted as different if they correspond to different index selections.

Example 1:

Input: nums = [3, 5, 8, 10], k = 2

Output: 8

Explanation:

Valid beautiful subsets include: [3], [5], [8], [10], [3,8], [3,10], [5,8], [5,10], [8,10], [3,5,8], [3,8,10] (For example, [3,5] is invalid because |3 - 5| = 2 = k.)

Example 2:

Input: nums = [4, 7, 9], k = 3

Output: 5

Explanation:

Beautiful subsets: [4], [7], [9], [4,9], [7,9]

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result