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 ; Prthe time required ; Driver Code ; Function Call
def findMinimumTime ( p , n , target ) : NEW_LINE INDENT um = { } NEW_LINE for i in range ( n ) : NEW_LINE INDENT um [ p [ i ] ] = um . get ( p [ i ] , 0 ) + 1 NEW_LINE DEDENT time = 0 NEW_LINE sum = 0 NEW_LINE while ( sum < target ) : NEW_LINE INDENT sum = 0 NEW_LINE time += 1 NEW_LINE for it in um : NEW_LINE INDENT sum += um [ it ] * ( time // it ) NEW_LINE DEDENT DEDENT print ( time ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 3 , 3 , 4 ] NEW_LINE N = len ( arr ) NEW_LINE target = 10 NEW_LINE findMinimumTime ( arr , N , target ) NEW_LINE DEDENT