We have an array of integers,Continue reading “[Leetcode]1589. Maximum Sum Obtained of Any Permutation”`nums`

, and an array of`requests`

where`requests[i] = [start`

. The_{i}, end_{i}]`i`

request asks for the sum of^{th}`nums[start`

. Both_{i}] + nums[start_{i}+ 1] + ... + nums[end_{i}- 1] + nums[end_{i}]`start`

and_{i}`end`

are_{i}0-indexed. Returnthe maximum total sum of all requestsamong all permutationsof`nums`

. Since the answer may be too large, return itmodulo`10`

.^{9}+ 7

## [Leetcode]1590. Make Sum Divisible by P

Given an array of positive integersContinue reading “[Leetcode]1590. Make Sum Divisible by P”`nums`

, remove thesmallestsubarray (possiblyempty) such that thesumof the remaining elements is divisible by`p`

. It isnotallowed to remove the whole array. Returnthe length of the smallest subarray that you need to remove, or`-1`

if it's impossible. Asubarrayis defined as a contiguous block of elements in the array.

## [Leetcode problems]1477. Find Two Non-overlapping Sub-arrays Each With Target Sum

Given an array of integersContinue reading “[Leetcode problems]1477. Find Two Non-overlapping Sub-arrays Each With Target Sum”`arr`

and an integer`target`

. You have to findtwo non-overlapping sub-arraysof`arr`

each with sum equal`target`

. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays isminimum. Returnthe minimum sum of the lengthsof the two required sub-arrays, or returnif you cannot find such two sub-arrays.-1Example 1:Input:arr = [3,2,2,4,3], target = 3Output:2Explanation:Only two sub-arrays have sum = 3 ([3] and [3]). The sum of their lengths is 2.Example 2:Input:arr = [7,3,4,7], target = 7Output:2Explanation:Although we have three non-overlapping sub-arrays of sum = 7 ([7], [3,4] and [7]), but we will choose the first and third sub-arrays as the sum of their lengths is 2.