Question bank › Two Pointers
Dsa Two Pointers Easy

Temperature Fluctuation Range

A weather station records daily temperatures over a period of days. You are given an array of integers representing the daily temperatures. Write a function to find the maximum range of consecutive days where the temperature difference between the highest and lowest temperature is at most a given threshold. Input Format: - The first line contains two integers n (1 ≤ n ≤ 1000) — the number of days, and t (0 ≤ t ≤ 100) — the temperature difference threshold. - The second line contains n space-separated integers a_i (−50 ≤ a_i ≤ 50) — the daily temperatures. Output Format: - Print the maximum length of the subarray that meets the temperature difference condition. Example: Input: 7 10 5 15 25 10 20 30 5 Output: 5

Key concepts

two_pointersarraysliding_window

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.