Skip to content

Practice Find the Sum of Subsequence Powers

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#3098
LeetCode Problem

Find the Sum of Subsequence Powers

Problem Statement

You are given an integer array nums of length n, and a positive integer k. The power of a subsequence is defined as the minimum absolute difference between any two elements in the subsequence. Return the sum of powers of all subsequences of nums which have length equal to k. Since the answer may be large, return it modulo 10^9 + 7.

Source: Find the Sum of Subsequence Powers on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,2,3,4], k = 3
Output
4

# Example 2

Input
nums = [2,2], k = 2
Output
0

# Example 3

Input
nums = [4,3,-1], k = 2
Output
10

Constraints

2 <= n == nums.length <= 50
-10^8 <= nums[i] <= 10^8
2 <= k <= n

Related LeetCode Problems

Practice more problems similar to Find the Sum of Subsequence Powers.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.