LeetCode 1856. Maximum Subarray Min-Product - 亚马逊高频题30

给定一个整数数组,找到具有最大最小乘积的非空子数组。利用单调栈求解,通过找到每个数的左侧和右侧下一个较小的数,计算子数组和,最终找到最大乘积。问题转化为求解每个数对应的最长增序列两端的元素,结合前缀和加速计算。
摘要由CSDN通过智能技术生成

The min-product of an array is equal to the minimum value in the array multiplied by the array's sum.

  • For example, the array [3,2,5] (minimum value is 2) has a min-product of 2 * (3+2+5) = 2 * 10 = 20.

Given an array of integers nums, return the maximum min-product of any non-empty subarray of nums. Since the answer may be large, return it modulo 109 + 7.

Note that the min-product should be maximized before performing the modulo operation. Testcases are generated such that the maximum min-product without modulo will fit in a 64-bit signed integer.

subarray is a contiguous part of an array.

Example 1:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值