Make an array strictly increasing by repeatedly subtracting and adding arr [ i | Java program for the above approach ; Function to check if an array can be made strictly increasing ; Traverse the given array arr [ ] ; Update the value of p , arr [ i ] , and arr [ i - 1 ] ; Traverse the given array ; Check if the array arr [ ] is strictly increasing or not ; Otherwise , array is increasing order , print Yes ; Driver Code
import java . io . * ; class GFG { static void check ( int arr [ ] , int n ) { for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i - 1 ] >= ( i - 1 ) ) { int p = arr [ i - 1 ] - ( i - 1 ) ; arr [ i ] += p ; arr [ i - 1 ] -= p ; } } for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] <= arr [ i - 1 ] ) { System . out . println ( " No " ) ; return ; } } System . out . println ( " Yes " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 5 , 2 , 7 , 6 } ; int N = arr . length ; check ( arr , N ) ; } }