Minimum number of decrements by 1 required to reduce all elements of a circular array to 0 | Java program for the above approach ; Function to find minimum operation require to make all elements 0 ; Stores the maximum element and its position in the array ; Traverse the array ; Update the maximum element and its index ; Print the minimum number of operations required ; Driver Code
import java . io . * ; class GFG { static void minimumOperations ( int arr [ ] , int N ) { int mx = 0 , pos = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] >= mx ) { mx = arr [ i ] ; pos = i ; } } System . out . println ( ( mx - 1 ) * N + pos + 1 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 0 , 2 } ; int N = arr . length ; minimumOperations ( arr , N ) ; } }