Problem1075--shortest subarray

1075: shortest subarray

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 128 MiB

Description

You are given a 0-indexed array nums and an integer target.

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.



  • 1 <= nums.length <= 100,000
  • 1 <= nums[i] <= 100,000
  • 1 <= target <= 1000,000,000

Input

First line contains N and T (N is the length of nums and T is the target
second line contains N integers 

Output

one integer which is the size of the shortest subarray or -1 

Sample Input Copy

3 5
1 2 3

Sample Output Copy

2

HINT

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.

Source/Category