Minimum time required to reach a given score | Function to calculate minimum time required to achieve given score target ; Store the frequency of elements ; Traverse the array p [ ] ; Update the frequency ; Stores the minimim time required ; Store the current score at any time instant t ; Iterate until sum is at least equal to target ; Increment time with every iteration ; Traverse the map ; Increment the points ; Print the time required ; Driver Code ; Function Call
function findMinimumTime ( p , n , target ) { let um = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( um [ p [ i ] ] ) um [ p [ i ] ] ++ ; else um [ p [ i ] ] = 1 } let time = 0 ; let sum = 0 ; while ( sum < target ) { sum = 0 ; time ++ ; for ( let it in um ) { sum += um [ it ] * Math . floor ( time / it ) ; } } document . write ( time ) ; } let arr = [ 1 , 3 , 3 , 4 ] ; let N = arr . length ; let target = 10 ; findMinimumTime ( arr , N , target ) ;