Find non | JavaScript program for the above approach ; Function to find the possible output array ; Base case for the recursion ; If ind becomes half of the size then print the array . ; Exit the function . ; Iterate in the range . ; Put the values in the respective indices . ; Call the function to find values for other indices . ; Driver Code
const INF64 = 1000000000000000000 ; const N = 200 * 1000 + 13 ; let n ; let arr = Array ( N ) ; let brr = Array ( N ) ; function brute ( ind , l , r ) { if ( ind == n / 2 ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( brr [ i ] + " " ) ; exit ( 0 ) ; } for ( let i = l ; i <= arr [ ind ] / 2 ; ++ i ) if ( arr [ ind ] - i <= r ) { brr [ ind ] = i ; brr [ n - ind - 1 ] = arr [ ind ] - i ; brute ( ind + 1 , i , arr [ ind ] - i ) ; } } n = 2 ; n *= 2 ; arr [ 0 ] = 5 ; arr [ 1 ] = 6 ; brute ( 0 , 0 , INF64 ) ;