Question Details

No question body available.

Tags

python arrays numpy

Answers (1)

January 31, 2026 Score: 1 Rep: 100 Quality: Low Completeness: 50%

The key is to find runs of positive differences that are long enough.

import numpy as np

def monotonic_starts(arr, n): arr = np.asarray(arr)

# 1: Find where arr is increasing increasing = np.diff(arr) > 0

# 2: Pad with False to detect run boundaries at edges padded = np.concatenate([[False], increasing, [False]])

# 3: Find run starts (+1) and ends (-1) edges = np.diff(padded.astype(int)) starts = np.where(edges == 1)[0] ends = np.where(edges == -1)[0]

# 4: Filter runs with at least (n-1) consecutive increases lengths = ends - starts return starts[lengths >= n - 1]