Skip to content

Practice Minimum Size Subarray in Infinite Array

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2875
LeetCode Problem

Minimum Size Subarray in Infinite Array

Problem Statement

You are given a 0-indexed array nums and an integer target. A 0-indexed array infinite_nums is generated by infinitely appending the elements of nums to itself. Return the length of the shortest subarray of the array infinite_nums with a sum equal to target. If there is no such subarray return -1.

Source: Minimum Size Subarray in Infinite Array on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,2,3], target = 5
Output
2

# Example 2

Input
nums = [1,1,1,2,3], target = 4
Output
2

# Example 3

Input
nums = [2,4,6,8], target = 3
Output
-1

Constraints

1 <= nums.length <= 10^5
1 <= nums[i] <= 10^5
1 <= target <= 10^9

Related LeetCode Problems

Practice more problems similar to Minimum Size Subarray in Infinite Array.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.