Minimum time required to reach a given score | C # program for the above approach ; 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
using System . Collections . Generic ; using System ; using System . Linq ; class GFG { static void findMinimumTime ( int [ ] p , int n , int target ) { Dictionary < int , int > um = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( um . ContainsKey ( p [ i ] ) == true ) um [ p [ i ] ] += 1 ; else um [ p [ i ] ] = 1 ; } int time = 0 ; int sum = 0 ; var val = um . Keys . ToList ( ) ; while ( sum < target ) { sum = 0 ; time ++ ; foreach ( var key in val ) { sum += um [ key ] * ( time / key ) ; } } Console . WriteLine ( time ) ; } public static void Main ( ) { int [ ] arr = { 1 , 3 , 3 , 4 } ; int N = arr . Length ; int target = 10 ; findMinimumTime ( arr , N , target ) ; } }