#3098

Find the Sum of Subsequence Powers

hard · 25.1% accepted · 148 likes · top 4%

array · dynamic programming · sorting

⊣ practice⊣ open on leetcode ↗

Description

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 109 + 7.

Solution