Practice Maximum Product of First and Last Elements of a Subsequence
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Medium#3584
LeetCode ProblemMaximum Product of First and Last Elements of a Subsequence
Problem Statement
You are given an integer array nums and an integer m. Return the maximum product of the first and last elements of any subsequence of nums of size m.
Source: Maximum Product of First and Last Elements of a Subsequence on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
nums = [-1,-9,2,3,-2,-3,1], m = 1
Output
81
# Example 2
Input
nums = [1,3,-5,5,6,-4], m = 3
Output
20
# Example 3
Input
nums = [2,-1,2,-6,5,2,-5,7], m = 2
Output
35
Constraints
1 <= nums.length <= 10^5
-10^5 <= nums[i] <= 10^5
1 <= m <= nums.length
Related LeetCode Problems
Practice more problems similar to Maximum Product of First and Last Elements of a Subsequence.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.