0
Leetcode Problem 896. Monotonic Array
896. Monotonic Array
AI Mock Interview
Leetcode Solutions
Approach: Two Pass
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Initialize two boolean variables,
increasing
and
decreasing
, to
true
.
Iterate over the array from the first element to the second-to-last element.
If
nums[i] > nums[i+1]
, set
increasing
to
false
.
If
nums[i] < nums[i+1]
, set
decreasing
to
false
.
After the loop, if either
increasing
or
decreasing
is
true
, return
true
.
If neither is
true
, return
false
.
Approach: One Pass (Simple Variant)
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Full Screen
Copy Answer Code
Loading...