Minimum increments by index value required to obtain at least two equal Array elements | Java program to implement the above approach ; Function to calculate the minimum number of steps required ; Stores minimum difference ; Driver code
import java . util . * ; class GFG { static void incrementCount ( int arr [ ] , int N ) { int mini = arr [ 0 ] - arr [ 1 ] ; for ( int i = 2 ; i < N ; i ++ ) { mini = Math . min ( mini , arr [ i - 1 ] - arr [ i ] ) ; } System . out . println ( mini ) ; } public static void main ( String [ ] args ) { int N = 3 ; int arr [ ] = { 12 , 8 , 4 } ; incrementCount ( arr , N ) ; } }