leetle

Daily challenge for 2026-07-07

553. Longest Bounded Elevation Ascent

You are planning a hiking trail and want to find the longest continuous uphill section (where each step is at least as high as the previous step) such that the total elevation gain (the difference between the last and first point of the section) is at most k.

Given an array of integers altitudes and an integer k, return the length of the longest contiguous non-decreasing subarray where the difference between its last element and its first element is at most k.

Example:
Input: altitudes = [1, 2, 4, 4, 7, 8], k = 3
Output: 4
Explanation: The longest valid section is [1, 2, 4, 4] with length 4. The elevation gain is 4 - 1 = 3, which is <= 3.

Run this challenge interactively in Python or JavaScript when the app loads.