Smallest array that can be obtained by replacing adjacent pairs with their products | Java implementation of the above approach ; Function to minimize the size of array by performing given operations ; If all array elements are not same ; If all array elements are same ; Driver Code ; Function call
import java . io . * ; class GFG { static int minLength ( int arr [ ] , int N ) { for ( int i = 1 ; i < N ; i ++ ) { if ( arr [ 0 ] != arr [ i ] ) { return 1 ; } } return N ; } public static void main ( String [ ] args ) { int [ ] arr = { 2 , 1 , 3 , 1 } ; int N = arr . length ; System . out . print ( minLength ( arr , N ) ) ; } }