Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Home
Talentd Logo
Talentd

Your trusted platform to ace any job interviews, craft the perfect resumes, and land your dream jobs.

P
Featured on
Product Hunt
▲455
All services are online

Products

  • Resume Review
  • Company Prep Pack
  • DSA Corner
  • Jobs
  • Internships
  • Fresher Jobs
  • Roadmaps
  • Tax Calculator

Resources

  • Articles
  • DRDO Internships

Support

  • Contact Us

DSA & Interview Prep

  • DSA Questions
  • DSA Sheets
  • Company Questions
  • Topics

Company

  • Companies Hiring
  • About
  • Contact
  • Advertisement

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Delivery Policy

Popular Skills

Browse All Skills →

Popular Tags

Browse All Tags →

© 2025 Talentd.in - All rights reserved

Privacy PolicyTerms & Conditions
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
DSA Corner
DashboardQuestionsTopicsCompaniesSheets

Talentd Logo
Talentd

Your trusted platform to ace any job interviews, craft the perfect resumes, and land your dream jobs.

P
Featured on
Product Hunt
▲455
All services are online

Products

  • Resume Review
  • Company Prep Pack
  • DSA Corner
  • Jobs
  • Internships
  • Fresher Jobs
  • Roadmaps
  • Tax Calculator

Resources

  • Articles
  • DRDO Internships

Support

  • Contact Us

DSA & Interview Prep

  • DSA Questions
  • DSA Sheets
  • Company Questions
  • Topics

Company

  • Companies Hiring
  • About
  • Contact
  • Advertisement

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Delivery Policy

Popular Skills

Browse All Skills →

Popular Tags

Browse All Tags →

© 2025 Talentd.in - All rights reserved

Privacy PolicyTerms & Conditions
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
DSA Corner
DashboardQuestionsTopicsCompaniesSheets
Talentd Logo
Talentd

Your trusted platform to ace any job interviews, craft the perfect resumes, and land your dream jobs.

P
Featured on
Product Hunt
▲455
All services are online

Products

  • Resume Review
  • Company Prep Pack
  • DSA Corner
  • Jobs
  • Internships
  • Fresher Jobs
  • Roadmaps
  • Tax Calculator

Resources

  • Articles
  • DRDO Internships

Support

  • Contact Us

DSA & Interview Prep

  • DSA Questions
  • DSA Sheets
  • Company Questions
  • Topics

Company

  • Companies Hiring
  • About
  • Contact
  • Advertisement

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Delivery Policy

Popular Skills

Browse All Skills →

Popular Tags

Browse All Tags →

© 2025 Talentd.in - All rights reserved

Privacy PolicyTerms & Conditions
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
DSA Corner
DashboardQuestionsTopicsCompaniesSheets
Talentd Logo
Talentd

Your trusted platform to ace any job interviews, craft the perfect resumes, and land your dream jobs.

P
Featured on
Product Hunt
▲455
All services are online

Products

  • Resume Review
  • Company Prep Pack
  • DSA Corner
  • Jobs
  • Internships
  • Fresher Jobs
  • Roadmaps
  • Tax Calculator

Resources

  • Articles
  • DRDO Internships

Support

  • Contact Us

DSA & Interview Prep

  • DSA Questions
  • DSA Sheets
  • Company Questions
  • Topics

Company

  • Companies Hiring
  • About
  • Contact
  • Advertisement

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Delivery Policy

Popular Skills

Browse All Skills →

Popular Tags

Browse All Tags →

© 2025 Talentd.in - All rights reserved

Privacy PolicyTerms & Conditions
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
DSA Corner
DashboardQuestionsTopicsCompaniesSheets
Back to Problems

896. Monotonic Array

Easy61.4% Acceptance
Array
Asked by:
F
Facebook
M
Microsoft
ProblemSolutions (12)VideosCompanies (4)Notes

Problem Statement

An array is monotonic if it is either monotone increasing or monotone decreasing.

An array nums is monotone increasing if for all i <= j, nums[i] <= nums[j]. An array nums is monotone decreasing if for all i <= j, nums[i] >= nums[j].

Given an integer array nums, return true if the given array is monotonic, or false otherwise.

Example 1:

Input: nums = [1,2,2,3]
Output: true

Example 2:

Input: nums = [6,5,4,4]
Output: true

Example 3:

Input: nums = [1,3,2]
Output: false

Constraints:

  • 1 <= nums.length <= 105
  • -105 <= nums[i] <= 105
Talentd Logo
Talentd

Your trusted platform to ace any job interviews, craft the perfect resumes, and land your dream jobs.

P
Featured on
Product Hunt
▲455
All services are online

Products

  • Resume Review
  • Company Prep Pack
  • DSA Corner
  • Jobs
  • Internships
  • Fresher Jobs
  • Roadmaps
  • Tax Calculator

Resources

  • Articles
  • DRDO Internships

Support

  • Contact Us

DSA & Interview Prep

  • DSA Questions
  • DSA Sheets
  • Company Questions
  • Topics

Company

  • Companies Hiring
  • About
  • Contact
  • Advertisement

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Delivery Policy

Popular Skills

Browse All Skills →

Popular Tags

Browse All Tags →

© 2025 Talentd.in - All rights reserved

Privacy PolicyTerms & Conditions
T
TikTok
A
Amazon

Approach

The goal of #896 Monotonic Array is to determine whether a given array is entirely non-increasing or non-decreasing. A monotonic array maintains a consistent order across all adjacent elements. Instead of sorting or using extra data structures, the key insight is to simply track the direction of comparisons while scanning the array once.

A common approach is to iterate through the array and compare each element with the next one. Maintain two logical indicators: one to check if the array can still be non-decreasing and another for non-increasing. If at any point a comparison violates one direction, you update the corresponding indicator. By the end of the traversal, if at least one direction remains valid, the array is monotonic.

This strategy works efficiently because it only requires a single pass through the array and uses constant extra space. The method avoids unnecessary sorting and keeps the solution optimal for interview settings.

Complexity

ApproachTime ComplexitySpace Complexity
Single Pass Direction CheckO(n)O(1)

Video Solution Available

Ashish Pratap Singh

View all video solutions

Solutions (12)

Single Pass Check for Monotonic Nature

This approach involves traversing the array and maintaining two flags: one for checking if the array elements are in increasing order and another for checking if they are in decreasing order. As we iterate through the array, we update these flags accordingly. If the array violates both conditions at any point, it is not monotonic.

Time Complexity: O(n), where n is the length of the array, since we perform a single traversal of the array.
Space Complexity: O(1), as no extra space is utilized apart from the flags.

CC++JavaPythonC#JavaScript
1#include <stdbool.h>
2
3bool isMonotonic(int* nums, int numsSize) {
4    bool increasing = true, decreasing = true;
5    for (

Explanation

We loop through the array, starting from the second element. We check if the current element is greater than or less than the previous element and update the respective flags (decreasing and increasing). If both conditions are violated for any element pair, the function returns false. At the end of the loop, if either flag remains true, it implies the array is monotonic.

Two Separate Passes for Increasing and Decreasing

In this approach, we perform two separate passes to test for monotonic increase and monotonic decrease independently. The first pass checks for strictly increasing nature, and the second checks for strictly decreasing nature.

Time Complexity: O(n), two passes over the array which are separate checks.
Space Complexity: O(1), with no additional space used beyond flags.

CC++JavaPythonC#JavaScript
1#


Video Solutions

Watch expert explanations and walkthroughs

LeetCode was HARD until I Learned these 15 Patterns

Ashish Pratap Singh
13:001,002,144 views

Asked By Companies

4 companies
F
Facebook
M
Microsoft
T
TikTok
A
Amazon

Prepare for Interviews

Practice problems asked by these companies to ace your technical interviews.

Explore More Problems

Notes

Personal Notes

Jot down your thoughts, approach, and key learnings

0 characters

Similar Problems

Two SumEasy
Median of Two Sorted ArraysHard
Container With Most WaterMedium
3SumMedium
More similar problems

Related Topics

Array

Problem Stats

Acceptance Rate61.4%
DifficultyEasy
Companies4

Practice on LeetCode

Solve with full IDE support and test cases

Solve Now

Frequently Asked Questions

Is Monotonic Array asked in FAANG interviews?

Yes, monotonic array concepts appear in coding interviews because they test basic array traversal and logical reasoning. While the exact problem may vary, similar patterns involving order checks and comparisons are common in technical interviews.

What is the optimal approach for Monotonic Array?

The optimal approach is to traverse the array once while checking whether it remains non-decreasing or non-increasing. By maintaining two direction flags during the scan, you can determine monotonicity efficiently without sorting. This results in O(n) time and O(1) space complexity.

What data structure is best for solving Monotonic Array?

No special data structure is required for this problem. A simple array traversal with a few boolean indicators is enough to track whether the order remains increasing or decreasing throughout the iteration.

How do you check if an array is monotonic without sorting?

You can compare each pair of adjacent elements while iterating through the array. Track whether the array still satisfies non-decreasing or non-increasing conditions. If at least one condition holds after the traversal, the array is monotonic.

int
i
=
1
;
i
<
numsSize
;
i
++
)
{
6
if
(
nums
[
i
]
>
nums
[
i
-
1
]
)
7
decreasing
=
false
;
8
if
(
nums
[
i
]
<
nums
[
i
-
1
]
)
9
increasing
=
false
;
10
}
11
return
increasing
||
decreasing
;
12
}
include
<stdbool.h>
2
3
bool
isIncreasing
(
int
*
nums
,
int
numsSize
)
{
4
for
(
int
i
=
1
;
i
<
numsSize
;
i
++
)
{
5
if
(
nums
[
i
]
<
nums
[
i
-
1
]
)
return
false
;
6
}
7
return
true
;
8
}
9
10
bool
isDecreasing
(
int
*
nums
,
int
numsSize
)
{
11
for
(
int
i
=
1
;
i
<
numsSize
;
i
++
)
{
12
if
(
nums
[
i
]
>
nums
[
i
-
1
]
)
return
false
;
13
}
14
return
true
;
15
}
16
17
bool
isMonotonic
(
int
*
nums
,
int
numsSize
)
{
18
return
isIncreasing
(
nums
,
numsSize
)
||
isDecreasing
(
nums
,
numsSize
)
;
19
}

Explanation

The C solution uses two helper functions, isIncreasing and isDecreasing, which independently check if the array is monotone increasing or decreasing. The main function returns true if either condition holds true.