The Monotonic Array problem asks you to determine whether a given array is either entirely non-increasing or entirely non-decreasing. An array is monotonic if it moves in only one direction. This Monotonic Array coding problem is a simple yet clean exercise in single-pass array reasoning.
Microsoft, Meta, Amazon, Google, Bloomberg, and Adobe ask this as a warm-up problem to evaluate code clarity and efficiency. It tests whether candidates can write a clean O(n) solution without unnecessarily complex logic. The array interview pattern is demonstrated here with precision.
Single pass with two flags. Track isIncreasing and isDecreasing as booleans. For each adjacent pair, if arr[i] > arr[i+1], set isDecreasing = false. If arr[i] < arr[i+1], set isIncreasing = false. If both become false, return false immediately. Return true at the end.
Array: [1, 3, 5, 5, 7].
Array: [5, 3, 4, 2].
Easy problems like Monotonic Array are tests of clean, minimal code. The two-flag single-pass approach is optimal and elegant. Avoid overcomplicating with sorting or multiple passes. In interviews, solving easy problems quickly and with clean code shows confidence and frees time for harder follow-ups. Practice writing this solution in under 5 minutes from scratch.