Dsa
Two Pointers
Easy
Temperature Anomaly
You are given an array of integers representing daily temperature readings. You need to return the length of the longest contiguous subarray in which the temperature readings differ by at least a specified value. If no such subarray exists, return 0.
Input:
- The first line contains an integer n (1 <= n <= 1000) - the length of the temperature readings.
- The second line contains n integers representing the temperatures.
- The third line contains an integer k (1 <= k <= 100) - the minimum difference.
Output:
- Return the length of the longest subarray with the required properties.
Example:
Input:
6
30 20 15 40 25 10
15
Output:
4
The longest subarray is from index 1 to 4 (20, 15, 40, 25).
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