#3509

Maximum Product of Subsequences With an Alternating Sum Equal to K

hard · 13% accepted · 57 likes · top 0%

array · hash table · dynamic programming

⊣ practice⊣ open on leetcode ↗

Description

You are given an integer array nums and two integers, k and limit. Your task is to find a non-empty subsequence of nums that:

- Has an alternating sum equal to k.

- Maximizes the product of all its numbers without the product exceeding limit.

Return the product of the numbers in such a subsequence. If no subsequence satisfies the requirements, return -1.

The alternating sum of a 0-indexed array is defined as the sum of the elements at even indices minus the sum of the elements at odd indices.

Solution