Find the final radiations of each Radiated Stations | Function to print the final radiations ; Function to create the array of the resultant radiations ; Resultant radiations ; Declaring index counter for left and right radiation ; Effective radiation for left and right case ; Radiation for i - th station ; Radiation increment for left stations ; Radiation increment for right stations ; Print the resultant radiation for each of the stations ; 1 - based indexing
function print ( rStation , n ) { for ( var i = 1 ; i <= n ; i ++ ) document . write ( rStation [ i ] + " " ) ; document . write ( " " ) ; } function radiated_Station ( station , n ) { var rStation = [ ] ; rStation . length = 6 ; rStation . fill ( 0 ) for ( var i = 1 ; i <= n ; i ++ ) { var li = i - 1 , ri = i + 1 ; var lRad = station [ i ] - 1 , rRad = station [ i ] - 1 ; rStation [ i ] += station [ i ] ; while ( li >= 1 && lRad >= 1 ) { rStation [ li -- ] += lRad -- ; } while ( ri <= n && rRad >= 1 ) { rStation [ ri ++ ] += rRad -- ; } } print ( rStation , n ) ; } var station = [ 0 , 7 , 9 , 12 , 2 , 5 ] var n = station . length - 1 ; radiated_Station ( station , n ) ;