Minimize difference between two sequences obtained by splitting first N powers of 2 | Function to partition first N powers of 2 into two subsequences with minimum difference between their sum ; Largest element in the first part ; Place N / 2 - 1 smallest elements in the first sequence ; Place remaining N / 2 elements in the second sequence ; Print the minimum difference ; Driver Code
function minimumDifference ( N ) { var sum1 = ( 1 << N ) , sum2 = 0 ; for ( i = 1 ; i < N / 2 ; i ++ ) sum1 += ( 1 << i ) ; for ( i = N / 2 ; i < N ; i ++ ) sum2 += ( 1 << i ) ; document . write ( sum1 - sum2 ) ; } var N = 4 ; minimumDifference ( N ) ;