Smallest array that can be obtained by replacing adjacent pairs with their products | 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
function minLength ( arr , N ) { for ( let i = 1 ; i < N ; i ++ ) { if ( arr [ 0 ] != arr [ i ] ) { return 1 ; } } return N ; } let arr = [ 2 , 1 , 3 , 1 ] ; let N = arr . length ; document . write ( minLength ( arr , N ) ) ;