Tap here to switch tabs
Problem
Submissions

Problem: Find Two Non-overlapping Subarrays With Target Sum

Find Two Non-overlapping Subarrays With Target Sum asks for two non-overlapping subarrays in a positive-integer array, each summing to the target. Return their minimum combined length or -1.

Statement

Given an array of positive integers arr and an integer target.

Find two non overlapping subarrays of arr such that the sum of elements in each subarray is equal to target.

Return the minimum possible sum of the lengths of the two subarrays. If two such subarrays cannot be found, return −1-1.

Constraints:

  • 1≤1 \leq arr.length ≤105\leq 10^5

  • 1≤1 \leq arr[i] ≤1000\leq 1000

  • 1≤1 \leq target ≤108\leq 10^8

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find Two Non-overlapping Subarrays With Target Sum

Find Two Non-overlapping Subarrays With Target Sum asks for two non-overlapping subarrays in a positive-integer array, each summing to the target. Return their minimum combined length or -1.

Statement

Given an array of positive integers arr and an integer target.

Find two non overlapping subarrays of arr such that the sum of elements in each subarray is equal to target.

Return the minimum possible sum of the lengths of the two subarrays. If two such subarrays cannot be found, return −1-1.

Constraints:

  • 1≤1 \leq arr.length ≤105\leq 10^5

  • 1≤1 \leq arr[i] ≤1000\leq 1000

  • 1≤1 \leq target ≤108\leq 10^8