Minimum increments by index value required to obtain at least two equal Array elements | C ++ Program to implement the above approach ; Function to calculate the minimum number of steps required ; Stores minimum difference ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void incrementCount ( int arr [ ] , int N ) { int mini = arr [ 0 ] - arr [ 1 ] ; for ( int i = 2 ; i < N ; i ++ ) { mini = min ( mini , arr [ i - 1 ] - arr [ i ] ) ; } cout << mini ; } int main ( ) { int N = 3 ; int arr [ N ] = { 12 , 8 , 4 } ; incrementCount ( arr , N ) ; return 0 ; }