#3428

Maximum and Minimum Sums of at Most Size K Subsequences

medium · 21.7% accepted · 147 likes · top 2%

array · math · dynamic programming · sorting · combinatorics

Description

You are given an integer array nums and a positive integer k. Return the sum of the maximum and minimum elements of all subsequences of nums with at most k elements.

Since the answer may be very large, return it modulo 109 + 7.

Solution