Data Structures19 sections · 729 units
Open in Course

A Harder Problem

Prefix sum + deque

Given an integer array numsnums and an integer kk, find the length of the shortest non-empty subarray with sum at least kk. Return 1-1 if no such subarray exists.

This problem combines prefix sums with monotonic deques. It's harder than sliding window maximum. Arrays can contain negative numbers, which is why a simple sliding window doesn't work.