#394 Longest Monotonic Subarray

Companies:
Yandex
Themes:
AlgorithmsArraysPractice

An array of numbers a_1, a_2, ..., a_n is given.

Find a monotonic subarray, meaning a strictly decreasing or strictly increasing contiguous segment, of maximum length and return the pair of its start and end indexes.

Examples:

[2, 7, 5, 4, 4, 3] -> [1, 3]
[1, 1] -> {1, 1} // or [0, 0]

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in