Shortest Winning Streak

Company: Commotion daiict_28thjuly

Difficulty: medium

Problem Statement

Alice plays a game for n days. On day i , she gains or loses a[i] coins. A negative value means she loses coins on that day. Alice wants to pick a consecutive run of days (a subarray) where she gains at least k coins in total, and she wants this run to be as short as possible. Find the length of the shortest run of consecutive days with a total gain of at least k . If no such run exists, output -1 . Input Format The first line contains two space-separated integers n and k : the number of days and the required total gain. The second line contains n space-separated integers a[1], a[2], ..., a[n] , the coin change on each day. Constraints 1 <= n <= 15000 -10^9 <= a[i] <= 10^9 1 <= k <= 2 * 10^13 Totals over a run can reach 1.5 * 10^13 in absolute value, so a 64-bit signed integer type is required for the sums. A 32-bit accumulator will overflow. Output Format Print a single integer: the length of the shortest consecutive run whose total is at least k , or -1 if no run qu