← Questions
Count subarrays that match a comparison pattern
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A pattern of length m holds 1 (the next value goes up), 0 (it stays equal) and -1 (it goes down). Count the subarrays of length m + 1 whose consecutive comparisons follow the pattern exactly. Turn the array into its sequence of comparisons first; the follow-up is doing it in linear time with KMP or a Z-function when the arrays are large.
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
