Count of vessels completely filled after a given time | JavaScript program to implement the above approach ; Function to find the number of completely filled vessels ; Store the vessels ; Assuming all water is present in the vessel at the first level ; Store the number of vessel that are completely full ; Traverse all the levels ; Number of vessel at each level is j ; Calculate the exceeded amount of water ; If current vessel has less than 1 unit of water then continue ; One more vessel is full ; If left bottom vessel present ; If right bottom vessel present ; Number of levels ; Number of seconds ; Function call
var n , t ; function FindNoOfFullVessels ( n , t ) { var Matrix = Array . from ( Array ( n ) , ( ) => Array ( n ) . fill ( 0 ) ) ; Matrix [ 0 ] [ 0 ] = t * 1.0 ; var ans = 0 ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = 0 ; j <= i ; j ++ ) { var exceededwater = Matrix [ i ] [ j ] - 1 ; if ( exceededwater < 0 ) continue ; ans ++ ; if ( i + 1 < n ) Matrix [ i + 1 ] [ j ] += ( exceededwater / 2 ) ; if ( i + 1 < n && j + 1 < n ) Matrix [ i + 1 ] [ j + 1 ] += ( exceededwater / 2 ) ; } } return ans ; } var N = 3 ; var T = 4 ; document . write ( FindNoOfFullVessels ( N , T ) ) ;