I am trying to solve this problem: Impressing the Boss. I am simply checking if the next element is smaller than the current element and this approach seems to pass half of the test cases but it is failing some. Please help in understanding the error in my approach. Here is my implementation:
asked 03 Apr '18, 10:37

Your code will fail for 8 6 6 9 9 198 9 try solving for these answered 03 Apr '18, 12:33

TAKE TWO CASES FOR new value addding either to previous or to next while(T) { int n; cin>>n; int arr[n],b[n]; for(int i=0;i<n;i++){ cin="">>arr[i]; b[i]=arr[i]; } int flag=0; for(int i=1;i<n;i++){ if(arr[i1]="">arr[i]){ /if(arr[i1]>arr[i+1]){ flag=1; wrong checking here consider the case: 8 6 6 break;}/ arr[i]=arr[i1],b[i1]=b[i];
break;
//cnt++;
}
}
bool a_is_ok=true,b_is_ok=true;
} return 0; } answered 03 Apr '18, 12:36
