#C2153. Minimum Size Subarray Sum

    ID: 45438 Type: Default 1000ms 256MiB

Minimum Size Subarray Sum

Minimum Size Subarray Sum

Given an integer array of length \( n \) and a target integer \( t \), your task is to find the length of the smallest contiguous subarray whose sum is greater than or equal to \( t \). If no such subarray exists, output 0.

This problem can be efficiently solved using the sliding window technique. Navigate through the array while maintaining a running sum and adjust the window boundaries to achieve the minimum length that satisfies the condition.

inputFormat

The input is given via standard input (stdin) in the following format:

  • The first line contains an integer \( n \), the length of the array.
  • The second line contains \( n \) space-separated integers representing the array elements.
  • The third line contains an integer \( t \), the target sum.

outputFormat

Output a single integer via standard output (stdout) representing the minimum length of a contiguous subarray whose sum is greater than or equal to \( t \). If no such subarray exists, output 0.

## sample
6
2 3 1 2 4 3
7
2