Ctrl K

Twin Rising Runs

Medium
A sensor stored its readings in the array readings. Find the largest k such that the array contains two pieces of length k that sit **back to back** (the second starts right where the first ends) and both strictly increase. Formally, you need an index a such that readings[a..a+k-1] and readings[a+k..a+2k-1] are both strictly increasing. A single element counts as an increasing piece, so the answer is always at least 1. Return the largest such k.
Example 1
readings=[4, 6, 9, 1, 3, 8, 12, 0] → 3

The pieces [4, 6, 9] and [1, 3, 8] sit right next to each other and both strictly increase, so k = 3. No two neighbouring rising pieces of length 4 exist.

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

The whole array rises, so it can be cut in half: [1, 2, 3] and [4, 5, 6].

Example 3
readings=[7, 7, 7] → 1

Nothing strictly rises here, but pieces of length 1 always count as rising: [7] and [7].

Constraints
  • 2 ≤ len(readings) ≤ 2·10⁵
  • -10⁹ ≤ readings[i] ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsFind in a Shifted Sorted Array MediumFirst and Last Copy MediumFind in a Row-Chained Grid MediumFind in a Shifted Array With Repeats MediumMinimum of a Shifted List Medium
loading Python…
Input
readings=[4, 6, 9, 1, 3, 8, 12, 0]
Expected
3

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