We have an array of integers,
Continue reading “[Leetcode]1589. Maximum Sum Obtained of Any Permutation”
nums, and an array of
requests[i] = [starti, endi]. The
ith request asks for the sum of
nums[starti] + nums[starti + 1] + ... + nums[endi - 1] + nums[endi]. Both
endi are 0-indexed.
Return the maximum total sum of all requests among all permutations of
Since the answer may be too large, return it modulo
109 + 7.
Given an array of positive integers
Continue reading “[Leetcode]1590. Make Sum Divisible by P”
nums, remove the smallest subarray (possibly empty) such that the sum of the remaining elements is divisible by
p. It is not allowed to remove the whole array.
Return the length of the smallest subarray that you need to remove, or
-1 if it's impossible.
A subarray is defined as a contiguous block of elements in the array.
Given an array of integers
Continue reading “[Leetcode problems]1477. Find Two Non-overlapping Sub-arrays Each With Target Sum”
arr and an integer
You have to find two non-overlapping sub-arrays of
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 is minimum.
Return the minimum sum of the lengths of the two required sub-arrays, or return -1 if you cannot find such two sub-arrays.
Input: arr = [3,2,2,4,3], target = 3 Output: 2 Explanation: Only two sub-arrays have sum = 3 ( and ). The sum of their lengths is 2.
Input: arr = [7,3,4,7], target = 7 Output: 2 Explanation: Although we have three non-overlapping sub-arrays of sum = 7 (, [3,4] and ), but we will choose the first and third sub-arrays as the sum of their lengths is 2.