Ctrl K

Two Rises in a Row

Easy
A weather station logs sensor values in the array readings. An analyst wants to know whether the value climbed steadily for two periods in a row. Decide whether the array contains two **adjacent** windows of length length that are both strictly increasing. Adjacent means the second window starts right where the first one ends: if the first covers indices a … a + length - 1, the second covers a + length … a + 2·length - 1. Nothing is required at the seam: the last value of the first window may be larger than the first value of the second. Return true if such a pair exists and false otherwise.
Example 1
readings=[4, 6, 9, 1, 3, 8, 2], length=3 → True

[4, 6, 9] is strictly rising and right after it comes [1, 3, 8], which rises too. They sit back to back.

Example 2
readings=[1, 2, 3, 3, 4, 5], length=3 → True

The only back-to-back pair of length-3 windows is [1, 2, 3] and [3, 4, 5]. Both rise, so the answer is true. With length=4 it would be false.

Example 3
readings=[5, 5, 5, 5], length=1 → True
Constraints
  • 2 ≤ len(readings) ≤ 100
  • -1000 ≤ readings[i] ≤ 1000
  • 1 ≤ length, 2 · length ≤ len(readings)
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPair With a Target Sum EasySqueeze Repeats Out of a Sorted Array EasyDrop the Unwanted Value EasySlot on a Sorted Shelf EasyAdd One to a Digit Array Easy
loading Python…
Input
readings=[4, 6, 9, 1, 3, 8, 2], length=3
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 125 tests on the server, hidden ones included.