Minimum time required to reach a given score | Java 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
import java . util . * ; import java . io . * ; class GFG { static void findMinimumTime ( int [ ] p , int n , int target ) { HashMap < Integer , Integer > um = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! um . containsKey ( p [ i ] ) ) um . put ( p [ i ] , 1 ) ; else um . put ( p [ i ] , um . get ( p [ i ] ) + 1 ) ; } int time = 0 ; int sum = 0 ; while ( sum < target ) { sum = 0 ; time ++ ; for ( Map . Entry < Integer , Integer > it : um . entrySet ( ) ) { sum += it . getValue ( ) * ( time / it . getKey ( ) ) ; } } System . out . println ( time ) ; } public static void main ( String args [ ] ) { int [ ] arr = { 1 , 3 , 3 , 4 } ; int N = arr . length ; int target = 10 ; findMinimumTime ( arr , N , target ) ; } }