Question bank › Sliding Window
Dsa Sliding Window Easy

The Eco-Hiker

A hiker is planning a segment of a trail. Each mile has an elevation gain (positive integer). The hiker wants to find the SMALLEST continuous stretch of miles where the total elevation gain is at least K. However, the hiker refuses to traverse any mile that has an elevation gain strictly greater than a 'safety limit' S. If no such stretch exists, output -1. Example: Input: 6 15 10 5 8 12 4 6 7 Output: 3 Explanation: K=15, S=10. The mile with gain 12 is ignored. The stretch [4, 6, 7] sums to 17 (>= 15) and its length is 3.

Key concepts

sliding_windowoptimization

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.