Non-Decreasing Array Problem Statement

Given an integer array ARR of size N, determine if it can be transformed into a non-decreasing array by modifying at most one element.

An array is defined as non-decreasing if ARR[i] <= ARR[i + 1] for every index i where 0 <= i <= N - 2.

Input:

The first line contains an integer 'T' representing the number of test cases. For each test case, the input consists of:
  • An integer N indicating the size of the array.
  • A second line with N space-separated integers representing the array ARR.

Output:

For each test case, output "true" if the array can be made non-decreasing by modifying at most one element, otherwise output "false".

Example:

Input:
2
4
4 2 3 3
5
4 2 1 5 7
Output:
true
false

Constraints:

  • 1 <= T <= 50
  • 1 <= N <= 10^4
  • -10^9 <= ARR[i] <= 10^9

Note:

You do not need to print anything yourself. Implement the given function to solve the problem.
AnswerBot
4mo

Determine if an array can be transformed into a non-decreasing array by modifying at most one element.

  • Iterate through the array and check if there are more than one decreasing elements.

  • If there is onl...read more

Help your peers!
Select
Add answer anonymously...

Citicorp Software Developer interview questions & answers

A Software Developer was asked 9mo agoQ. How do you move all zeros to the end of an array using data structures and algor...read more
A Software Developer was asked Q. How can a Chemical Engineer contribute to Citi?
A Software Developer was asked Q. Ways To Make Coin Change Given an infinite supply of coins of varying denominati...read more

Popular interview questions of Software Developer

A Software Developer was asked 10mo agoQ1. How do you move all zeros to the end of an array using data structures and algor...read more
A Software Developer was asked Q2. How can a Chemical Engineer contribute to Citi?
A Software Developer was asked Q3. Ways To Make Coin Change Given an infinite supply of coins of varying denominati...read more
Citicorp Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits