Practice Find Two Non-overlapping Sub-arrays Each With Target Sum
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Find Two Non-overlapping Sub-arrays Each With Target Sum
Problem Statement
You are given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with a 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.
Source: Find Two Non-overlapping Sub-arrays Each With Target Sum on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
arr = [3,2,2,4,3], target = 3
2
# Example 2
arr = [7,3,4,7], target = 7
2
# Example 3
arr = [4,3,2,6,2,3,4], target = 6
-1
Constraints
Related LeetCode Problems
Practice more problems similar to Find Two Non-overlapping Sub-arrays Each With Target Sum.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.