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 arrayARR
.
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
1y
The solution checks if an integer array can become non-decreasing by modifying at most one element.
Iterate through the array and check if there are more than one decreasing pairs of elements.
If there ...read more
IRFAN BEG
6mo
good decision
IRFAN BEG
6mo
thats called time waisting please call me & joined the date
Add answer anonymously...
Top Josh Technology Group Front end Developer interview questions & answers
Popular interview questions of Front end Developer
Top HR questions asked in Josh Technology Group Front end Developer
>
Josh Technology Group Front end Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app