Skip to content

Practice Maximum and Minimum Sums of at Most Size K Subsequences

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

Medium#3428
LeetCode Problem

Maximum and Minimum Sums of at Most Size K Subsequences

Problem Statement

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 10^9 + 7.

Source: Maximum and Minimum Sums of at Most Size K Subsequences on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

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

# Example 2

Input
nums = [5,0,6], k = 1
Output
2 2

# Example 3

Input
nums = [1,1,1], k = 2
Output
12

Constraints

1 <= nums.length <= 10^5
0 <= nums[i] <= 10^9
1 <= k <= min(70, nums.length)

Related LeetCode Problems

Practice more problems similar to Maximum and Minimum Sums of at Most Size K Subsequences.

Review your practice with PhantomCodeAI

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