Prefix Factorials of a Prefix Sum Array | Function to find the factorial of prefix sum at every possible index ; Find the prefix sum array ; Stores the factorial of all the element till the sum of array ; Find the factorial array ; Find the factorials of each array element ; Print the resultant array ; Driver Code
function prefixFactorialArray ( A , N ) { for ( let i = 1 ; i < N ; i ++ ) { A [ i ] += A [ i - 1 ] ; } let fact = new Array ( A [ N - 1 ] + 1 ) ; fact [ 0 ] = 1 ; for ( let i = 1 ; i <= A [ N - 1 ] ; i ++ ) { fact [ i ] = i * fact [ i - 1 ] ; } for ( let i = 0 ; i < N ; i ++ ) { A [ i ] = fact [ A [ i ] ] ; } for ( let i = 0 ; i < N ; i ++ ) { document . write ( A [ i ] + " " ) ; } } let arr = [ 1 , 2 , 3 , 4 ] ; let N = arr . length prefixFactorialArray ( arr , N ) ;