Skip to content

Practice Maximum Product of Subsequences With an Alternating Sum Equal to K

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

Hard#3509
LeetCode Problem

Maximum Product of Subsequences With an Alternating Sum Equal to K

Problem Statement

Choose a nonempty subsequence of nums whose alternating sum equals k, adding its first selected value, subtracting the second, and continuing with alternating signs. Among such subsequences whose product is at most limit, return the largest product. Return -1 if no subsequence satisfies both requirements.

Source: Maximum Product of Subsequences With an Alternating Sum Equal to K on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,2,3], k = 2, limit = 10
Output
6

# Example 2

Input
nums = [0,2,3], k = -5, limit = 12
Output
-1

# Example 3

Input
nums = [2,2,3,3], k = 0, limit = 9
Output
9

Constraints

1 <= nums.length <= 150
0 <= nums[i] <= 12
-10^5 <= k <= 10^5
1 <= limit <= 5000

Related LeetCode Problems

Practice more problems similar to Maximum Product of Subsequences With an Alternating Sum Equal to K.

Review your practice with PhantomCodeAI

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