Tap here to switch tabs
Problem
Submissions

Problem: Find Two Non-overlapping Subarrays With Target Sum

med
30 min
Try to solve the Find Two Non-overlapping Subarrays With Target Sum problem.

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

med
30 min
Try to solve the Find Two Non-overlapping Subarrays With Target Sum problem.

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