Question bank › Sliding Window
Dsa Sliding Window Medium

Step-Up Marathon

An 'increment' is defined as a pair of adjacent elements where the second is strictly greater than the first (A[i] > A[i-1]). Given an array, find the length of the shortest contiguous window that contains at least K such increments. Input Format: - The first line contains an integer K. - The second line contains a space-separated sequence of integers. Output Format: - A single integer representing the minimum window length. If no such window exists, print 0. Example: Input: 2 1 2 1 2 3 Output: 3 (Explanation: Increments are at indices (0,1), (2,3), and (3,4). The window from index 2 to 4 is [1, 2, 3], which has two increments: (1,2) and (2,3). Its length is 3. The window from 0 to 3 is [1, 2, 1, 2] which also has two increments but length 4.)

Key concepts

sliding_windowtwo_pointers

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.