Check if array can be converted into strictly decreasing sequence | C ++ implementation to check that array can be converted into a strictly decreasing sequence ; Function to check that array can be converted into a strictly decreasing sequence ; Loop to check that each element is greater than the ( N - index ) ; If element is less than ( N - index ) ; If array can be converted ; Driver Code ; Function calling
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool check ( int * arr , int n ) { bool flag = true ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] < n - i ) { flag = false ; } } if ( flag ) { return true ; } else { return false ; } } int main ( ) { int arr1 [ ] = { 11 , 11 , 11 , 11 } ; int n1 = sizeof ( arr1 ) / sizeof ( arr1 [ 0 ] ) ; if ( check ( arr1 , n1 ) ) { cout << " Yes " << endl ; } else { cout << " No " << endl ; } }