My issue
My code is prefectly giving true answer of those test case but when i submit , no one test case is true.
My code
#include <bits/stdc++.h>
using namespace std;
void fun(){
int size;
//cout << "enter size of array";
cin >> size;
vector<int> arr (size);
vector<bool> isAdded (size, false);
// getting array
for(int i=0; i<size; i++){
//cout<<"enter arr["<<i<<"]";
cin >> arr[i];
}
int maxi = INT_MIN;
for(int i=1; i<size;){
if(arr[i] < arr[i-1]){
maxi = max(maxi, arr[i-1] - arr[i]);
isAdded[i] = true;
i+=2;
}
else{
i++;
}
}
for(int i=1 ; i<size; i++){
if(isAdded[i]){
arr[i] += maxi;
}
}
for(int i=1 ; i<size; i++){
if(arr[i] < arr[i-1]){
cout << "NO";
return;
}
}
cout << "YES";
}
int main() {
// your code goes here
int t;
cin >> t;
while(t--){
fun();
}
}
Problem Link: Disjoint Non-Decreasing Array Practice Coding Problem - CodeChef