Construct an Array of Strings having Longest Common Prefix specified by the given Array | Function to find the array of strings ; Marks the ( N + 1 ) th string ; To generate remaining N strings ; Find i - th string using ( i + 1 ) - th string ; Check if current character is b ; Otherwise ; Insert the string ; Return the answer ; Driver Code ; Print the strings
function solve ( n , arr ) { var s = [ ' ' , ' ' , ' ' ] var ans = [ ] ; ans . push ( s . join ( " " ) ) ; for ( var i = n - 1 ; i >= 0 ; i -- ) { if ( s . length - 1 >= arr [ i ] ) { var ch = s [ arr [ i ] ] ; if ( ch == ' ' ) ch = ' ' ; else ch = ' ' ; s [ arr [ i ] ] = ch ; } ans . push ( s . join ( " " ) ) ; } return ans ; } var arr = [ 2 , 0 , 3 ] ; var n = arr . length ; var ans = solve ( n , arr ) ; for ( var i = ans . length - 1 ; i >= 0 ; i -- ) { document . write ( ans [ i ] + " " ) ; }