


Minimum Number of Days to Make ‘m’ Bouquets - Given an integer array bloomDay, an integer m and an integer k. If present then the current prefix length + width is a possible candidate. Next in ‘prefix_sums’ repeat to check if ‘s-target’ is present at index i. At index i check if ‘s-target’ is present in ‘suffix_sums’ then compute the minimum length and update in width. For an index i, store the minimum length of sub-array in i to len(arr)-1 with sum ‘target’ in an array ‘width’. The sum of their lengths is 2.Īpproach - Use a hash map ‘suffix_sums’ to store the running sum from index i to len(arr)-1. Return the minimum sum of the lengths of the two required sub-arrays, or return -1 if you cannot find such two sub-arrays.Įxample: Input: arr =, target = 3 Output: 2 Explanation: Only two sub-arrays have sum = 3 ( and ). 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. You have to find two non-overlapping sub-arrays of arreach with sum equal target. Find Two Non-overlapping Sub-arrays Each With Target Sum - Given an array of integers arr and an integer target.
