Find permutation with maximum remainder Sum | Function to find the permutation ; Put n at the first index 1 ; Put all the numbers from 2 to n sequentially ; Driver code ; Display the permutation
function Findpermutation ( n ) { let a = new Array ( n + 1 ) ; a [ 1 ] = n ; for ( let i = 2 ; i <= n ; i ++ ) a [ i ] = i - 1 ; return a ; } let n = 8 ; let v = Findpermutation ( n ) ; for ( let i = 1 ; i <= n ; i ++ ) document . write ( v [ i ] + ' ' ) ;