Dsa
Two Pointers
Easy
Temperature Range
You are given an array of daily temperatures in Celsius. Your task is to find and print the longest contiguous subarray where the difference between the maximum and minimum temperature does not exceed a specified threshold 'k'.
Input Format:
The first line contains an integer n, the number of days.
The second line contains n space-separated integers representing temperatures.
The third line contains an integer k, the maximum allowable temperature difference.
Output Format:
Print the length of the longest contiguous subarray that meets the criteria.
Example:
Input:
7
30 40 35 32 42 38 36
5
Output:
5
Key concepts
two_pointersarrays
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