Algorithms
Medium
2875
3141
Minimum Size Subarray in Infinite Array
minimum-size-subarray-in-infinite-array
"""
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.

Example 1:

Input: nums = [1,2,3], target = 5
Output: 2
Explanation: In this example infinite_nums = [1,2,3,1,2,3,1,2,...].
The subarray in the range [1,2], has the sum equal to target = 5 and length = 2.
It can be proven that 2 is the shortest length of a subarray with sum equal to target = 5.

Example 2:

Input: nums = [1,1,1,2,3], target = 4
Output: 2
Explanation: In this example infinite_nums = [1,1,1,2,3,1,1,1,2,3,1,1,...].
The subarray in the range [4,5], has the sum equal to target = 4 and length = 2.
It can be proven that 2 is the shortest length of a subarray with sum equal to target = 4.

Example 3:

Input: nums = [2,4,6,8], target = 3
Output: -1
Explanation: In this example infinite_nums = [2,4,6,8,2,4,6,8,...].
It can be proven that there is no subarray with sum equal to target = 3.


Constraints:

 * 1 <= nums.length <= 105
 * 1 <= nums[i] <= 105
 * 1 <= target <= 109
"""
class Solution:
    def minSizeSubarray(self, nums: List[int], target: int) -> int:
        
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.

Example 1:

Input: nums = [1,2,3], target = 5
Output: 2
Explanation: In this example infinite_nums = [1,2,3,1,2,3,1,2,...].
The subarray in the range [1,2], has the sum equal to target = 5 and length = 2.
It can be proven that 2 is the shortest length of a subarray with sum equal to target = 5.

Example 2:

Input: nums = [1,1,1,2,3], target = 4
Output: 2
Explanation: In this example infinite_nums = [1,1,1,2,3,1,1,1,2,3,1,1,...].
The subarray in the range [4,5], has the sum equal to target = 4 and length = 2.
It can be proven that 2 is the shortest length of a subarray with sum equal to target = 4.

Example 3:

Input: nums = [2,4,6,8], target = 3
Output: -1
Explanation: In this example infinite_nums = [2,4,6,8,2,4,6,8,...].
It can be proven that there is no subarray with sum equal to target = 3.


Constraints:

 * 1 <= nums.length <= 105
 * 1 <= nums[i] <= 105
 * 1 <= target <= 109


Please complete the code below to solve above prblem:
```python
class Solution:
    def minSizeSubarray(self, nums: List[int], target: int) -> int:
        
```

my_solution = Solution()

test_input = { "nums": [1,2,3], "target": 5 }
assert my_solution.minSizeSubarray(**test_input) == 2

test_input = { "nums": [1,1,1,2,3], "target": 4 }
assert my_solution.minSizeSubarray(**test_input) == 2

test_input = { "nums": [2,4,6,8], "target": 3 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [2,1,5,7,7,1,6,3], "target": 39 }
assert my_solution.minSizeSubarray(**test_input) == 9

test_input = { "nums": [17,4,3,14,17,6,15], "target": 85 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [18,3,11,19,7,16,6,7,3,6,18,9,9,1,14,17,15,14,12,10], "target": 7 }
assert my_solution.minSizeSubarray(**test_input) == 1

test_input = { "nums": [2,3,5,2,3,4,4,1,3,5,2,2,5,1,1,2,5], "target": 19 }
assert my_solution.minSizeSubarray(**test_input) == 6

test_input = { "nums": [4,1,5,7,1,6,1,7,2,2,5,5,5,6,3], "target": 20 }
assert my_solution.minSizeSubarray(**test_input) == 5

test_input = { "nums": [7,3,5], "target": 36 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [1,11,6,4,13], "target": 22 }
assert my_solution.minSizeSubarray(**test_input) == 4

test_input = { "nums": [1,2,2,2,1,2,1,2,1,2,1], "target": 83 }
assert my_solution.minSizeSubarray(**test_input) == 53

test_input = { "nums": [4,3,5,4,5,4,4,4,5,7,4,5,6,3,1,4,6,3,7], "target": 15 }
assert my_solution.minSizeSubarray(**test_input) == 3

test_input = { "nums": [1,2,3,2,1,5,3,4,5], "target": 53 }
assert my_solution.minSizeSubarray(**test_input) == 19

test_input = { "nums": [2,5,6,4], "target": 95 }
assert my_solution.minSizeSubarray(**test_input) == 22

test_input = { "nums": [6,6,4,5,2,8,1,8,7,6,6,7,4,1,9,6,8,8], "target": 55 }
assert my_solution.minSizeSubarray(**test_input) == 9

test_input = { "nums": [1,2,8,19,17,2,3,11,8,12,16,18,7], "target": 36 }
assert my_solution.minSizeSubarray(**test_input) == 2

test_input = { "nums": [12,14,4,14,13,16,5], "target": 36 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], "target": 37 }
assert my_solution.minSizeSubarray(**test_input) == 37

test_input = { "nums": [5,7,2,6,4,1,6,7,1,4,7,6,7,7,6,6,4,6,8], "target": 90 }
assert my_solution.minSizeSubarray(**test_input) == 17

test_input = { "nums": [3,5,15,17,6,17,10,15,10,4,6], "target": 25 }
assert my_solution.minSizeSubarray(**test_input) == 2

test_input = { "nums": [14,5], "target": 23 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [1,1,5,9], "target": 68 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [11,1,17,14,9,16,5,3,7,16,14,18,17,10], "target": 82 }
assert my_solution.minSizeSubarray(**test_input) == 6

test_input = { "nums": [9,6,8,4,3,4,6,4,7,2,6,9,2,4,5,4], "target": 71 }
assert my_solution.minSizeSubarray(**test_input) == 14

test_input = { "nums": [2,4,4,3,2,3,2,5,3,1,5,1,4,2,6], "target": 23 }
assert my_solution.minSizeSubarray(**test_input) == 7

test_input = { "nums": [3,6], "target": 66 }
assert my_solution.minSizeSubarray(**test_input) == 15

test_input = { "nums": [1,4,8,5,9,8,8,2,3,1,6,2,7,5,5,3,3,5,6], "target": 57 }
assert my_solution.minSizeSubarray(**test_input) == 10

test_input = { "nums": [1,6,5,5,1,1,2,5,3,1,5,3,2,4,6,6], "target": 56 }
assert my_solution.minSizeSubarray(**test_input) == 16

test_input = { "nums": [5,3,5,4,3,1,3,3,1,3,3,5,5,4,5,5,5,5], "target": 8 }
assert my_solution.minSizeSubarray(**test_input) == 2

test_input = { "nums": [2,2,1,3,2,2,2,3,3,2,1,3,3,2,3,3], "target": 93 }
assert my_solution.minSizeSubarray(**test_input) == 40

test_input = { "nums": [5,1,4,1,5,6], "target": 71 }
assert my_solution.minSizeSubarray(**test_input) == 19

test_input = { "nums": [3,5,6,6,1,8,4,9,6,2,3,9,6,8,7,3,6,1,8,6], "target": 60 }
assert my_solution.minSizeSubarray(**test_input) == 11

test_input = { "nums": [12,15,9,3,3,12,13,14,7,11,7,15,12,5,11], "target": 18 }
assert my_solution.minSizeSubarray(**test_input) == 2

test_input = { "nums": [3,11,10,12,9,13,9], "target": 19 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [3,4,4], "target": 35 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [4,5,2,5,5,5,1], "target": 87 }
assert my_solution.minSizeSubarray(**test_input) == 23

test_input = { "nums": [2,13,15,3,6,7,16,7,9,10,4,3,12,9,13,2,9,13,15], "target": 4 }
assert my_solution.minSizeSubarray(**test_input) == 1

test_input = { "nums": [1,2,16,10,15,15,13,11,10,6,12,15,9], "target": 30 }
assert my_solution.minSizeSubarray(**test_input) == 2

test_input = { "nums": [3,5], "target": 85 }
assert my_solution.minSizeSubarray(**test_input) == 21

test_input = { "nums": [1,4,3,1,4,4,2,3], "target": 6 }
assert my_solution.minSizeSubarray(**test_input) == 2

test_input = { "nums": [2,10,12,10,4,4,12,5,12,12,5], "target": 33 }
assert my_solution.minSizeSubarray(**test_input) == 4

test_input = { "nums": [5,9,7,10,4,7,9,11,6,3,1,8,6,1,11,1,1], "target": 72 }
assert my_solution.minSizeSubarray(**test_input) == 11

test_input = { "nums": [19,18,6], "target": 56 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [3,5,7,6,5,3,7,7,1,5,3,1,5,6,3,1,6,1,3], "target": 20 }
assert my_solution.minSizeSubarray(**test_input) == 4

test_input = { "nums": [5,5,4,1,2,2,2,3,2,4,2,5], "target": 56 }
assert my_solution.minSizeSubarray(**test_input) == 16

test_input = { "nums": [1,1,1,1,1,1,1,1], "target": 22 }
assert my_solution.minSizeSubarray(**test_input) == 22

test_input = { "nums": [1,2], "target": 72 }
assert my_solution.minSizeSubarray(**test_input) == 48

test_input = { "nums": [4,3,6,6,2,6,1,6,7,5,7,6,1,5,7], "target": 82 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [4,1,5,2,3,1,2,4,1,5,3,3,5,2,6,6,5,2,1], "target": 63 }
assert my_solution.minSizeSubarray(**test_input) == 20

test_input = { "nums": [8,2,5,4,1,6,6,6,6,4,4,5,5,9,6,6,9,2], "target": 4 }
assert my_solution.minSizeSubarray(**test_input) == 1

test_input = { "nums": [18,12,13,9,17,11], "target": 82 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [13,3,1,5,13,7,12,5], "target": 35 }
assert my_solution.minSizeSubarray(**test_input) == 5

test_input = { "nums": [4,10,12,6,2,2,4,12,6,1,1,2,2,10,6,11,5,4,9], "target": 49 }
assert my_solution.minSizeSubarray(**test_input) == 7

test_input = { "nums": [8], "target": 68 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [7,2,6,7,6,4,4,1,6,4,1,7,7,2,2,4,4,4], "target": 29 }
assert my_solution.minSizeSubarray(**test_input) == 6

test_input = { "nums": [4,7,6,12,10,13,7,6,6,1,15,2,4,8,12], "target": 43 }
assert my_solution.minSizeSubarray(**test_input) == 6

test_input = { "nums": [4,10], "target": 10 }
assert my_solution.minSizeSubarray(**test_input) == 1

test_input = { "nums": [4,3,2,4,5,3,7,12,2,2,10], "target": 43 }
assert my_solution.minSizeSubarray(**test_input) == 8

test_input = { "nums": [1,1,1,1,1,1,1,1,1,1,1,1], "target": 58 }
assert my_solution.minSizeSubarray(**test_input) == 58

test_input = { "nums": [1,1,1,1,1], "target": 20 }
assert my_solution.minSizeSubarray(**test_input) == 20

test_input = { "nums": [4,3], "target": 23 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [3,2,1,3,2,1,3,1,1,1,2,1,2,1,2,3,3,1], "target": 78 }
assert my_solution.minSizeSubarray(**test_input) == 41

test_input = { "nums": [3,2,4,2,4,2,5,4,5,3,4,4,2,4,4,1], "target": 19 }
assert my_solution.minSizeSubarray(**test_input) == 5

test_input = { "nums": [17], "target": 1 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [10,12,1,11,9,5,4,5,1,10,8,12,5,4], "target": 82 }
assert my_solution.minSizeSubarray(**test_input) == 10

test_input = { "nums": [6], "target": 44 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [4,6,2,6,3,5,2,5,5,4,3,1,5,4,5,5,4,5,5,6], "target": 12 }
assert my_solution.minSizeSubarray(**test_input) == 3

test_input = { "nums": [14,4,13,12,18,8,4,15,4,14,17,4,2], "target": 8 }
assert my_solution.minSizeSubarray(**test_input) == 1

test_input = { "nums": [4,4,6,5,3,4,1,4,2,6,3], "target": 32 }
assert my_solution.minSizeSubarray(**test_input) == 9

test_input = { "nums": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], "target": 28 }
assert my_solution.minSizeSubarray(**test_input) == 28

test_input = { "nums": [5,10,1,3,14,7,13,6,5,7,10,3,10,5,8,5,7,5,6,7], "target": 25 }
assert my_solution.minSizeSubarray(**test_input) == 4

test_input = { "nums": [12,3,4,10,5,8,12,7,12,7,5,8,4,8,11,11], "target": 48 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [3,11,5,5,3,10,12,12,12,3,10], "target": 88 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [8,2,10,5], "target": 28 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [3,5,1,4,5,2,5,3,1,2,1,1,1,3,3,3,5], "target": 68 }
assert my_solution.minSizeSubarray(**test_input) == 23

test_input = { "nums": [1,4,1,4,4], "target": 21 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [15,8,8,19,8,12,15,3,15,8,10,9], "target": 77 }
assert my_solution.minSizeSubarray(**test_input) == 7

test_input = { "nums": [4,4], "target": 80 }
assert my_solution.minSizeSubarray(**test_input) == 20

test_input = { "nums": [4,9,3,7,5,4,5,1,3,5], "target": 69 }
assert my_solution.minSizeSubarray(**test_input) == 14

test_input = { "nums": [2,8,2,8,1,5,8,9,3,4,6,6,6,1,7,9], "target": 93 }
assert my_solution.minSizeSubarray(**test_input) == 17

test_input = { "nums": [7,11,14,12,3,16,11,9], "target": 10 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [2,1,2,1,3,2,1,1,2], "target": 17 }
assert my_solution.minSizeSubarray(**test_input) == 10

test_input = { "nums": [5,20,18,2,8], "target": 45 }
assert my_solution.minSizeSubarray(**test_input) == 4

test_input = { "nums": [2,1,2,1,2,1,1,1,2,2], "target": 58 }
assert my_solution.minSizeSubarray(**test_input) == 38

test_input = { "nums": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], "target": 17 }
assert my_solution.minSizeSubarray(**test_input) == 17

test_input = { "nums": [18,6,8,17,3,10,14,12,4,13,12,10,5,18,11], "target": 95 }
assert my_solution.minSizeSubarray(**test_input) == 9

test_input = { "nums": [19,12,14], "target": 57 }
assert my_solution.minSizeSubarray(**test_input) == 4

test_input = { "nums": [3,13,14], "target": 11 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [17,6,8,7,4,6,6,3,8,1,8,10,18,13,2], "target": 32 }
assert my_solution.minSizeSubarray(**test_input) == 3

test_input = { "nums": [3,12,4,9,5,2,2,9,9,6,9,11,9], "target": 41 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [3,14,2,9,5,14,15,4,3,4,17,11], "target": 3 }
assert my_solution.minSizeSubarray(**test_input) == 1

test_input = { "nums": [2,5,3,6,3,6,1,1,5,1], "target": 37 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [13,6,4,7,3,6,4,10,13,10,5,4,2,1,7,11,3,3,12], "target": 51 }
assert my_solution.minSizeSubarray(**test_input) == 7

test_input = { "nums": [1,10,9,16,3,10,2,5,1,10], "target": 83 }
assert my_solution.minSizeSubarray(**test_input) == 11

test_input = { "nums": [2,10,13,3,4,19,14,20,11,15,4,3,17,8,2,3,1,13,8], "target": 1 }
assert my_solution.minSizeSubarray(**test_input) == 1

test_input = { "nums": [4,5,5,3,5,4,2,11,5,9,4,6], "target": 41 }
assert my_solution.minSizeSubarray(**test_input) == 7

test_input = { "nums": [2,8,9,6,11,17,3,6,9,7,2,8,9,11,19], "target": 39 }
assert my_solution.minSizeSubarray(**test_input) == 3

test_input = { "nums": [8,13,9,5,8,6,17,16,14,7,10,15,16], "target": 8 }
assert my_solution.minSizeSubarray(**test_input) == 1

test_input = { "nums": [10,20,16,1,11,18,13,6,13,6,9,14,16,12,13,7,19], "target": 59 }
assert my_solution.minSizeSubarray(**test_input) == 5

test_input = { "nums": [1,1,1,1,1,1,1,1,1,1,1,1], "target": 6 }
assert my_solution.minSizeSubarray(**test_input) == 6