Minimum target-sum span

Medium · Arrays & hashing · Original CodeClash problem

Input has values and k. Return shortest nonempty contiguous subarray length summing exactly to k, or 0.

Input and output

One JSON value on a single line, with the fields described above. Read it using json.loads(input()).

One compact JSON value. Use print(json.dumps(answer, separators=(",", ":"))). Booleans must be JSON true/false. Arrays retain the stated order.

Examples

Example 1

Input: {"values":[1,2,1],"k":4}
Output: 3

Example 2

Input: {"values":[3,2,1],"k":1}
Output: 1

Constraints

Solve in Python

Sign in to save progress. Public example runs are unverified and do not affect ratings.