Minimum number of days required to complete the work | Java program to find the minimum number days required ; pair class for number of days ; Function to find the minimum number days required ; initialising ans to least value possible ; sort by first i . e D ( i ) ; Calculate the minimum possible days ; return the answer ; Driver Code ; Number of works ; D1 [ i ] ; D2 [ i ]
import java . util . * ; import java . lang . * ; import java . io . * ; class Pair { int x , y ; Pair ( int a , int b ) { this . x = a ; this . y = b ; } } class GFG { static int inf = Integer . MIN_VALUE ; public static int minimumDays ( int N , int D1 [ ] , int D2 [ ] ) { int ans = - inf ; ArrayList < Pair > list = new ArrayList < Pair > ( ) ; for ( int i = 0 ; i < N ; i ++ ) list . add ( new Pair ( D1 [ i ] , D2 [ i ] ) ) ; Collections . sort ( list , new Comparator < Pair > ( ) { @ Override public int compare ( Pair p1 , Pair p2 ) { return p1 . x - p2 . x ; } } ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( list . get ( i ) . y >= ans ) ans = list . get ( i ) . y ; else ans = list . get ( i ) . x ; } return ans ; } public static void main ( String [ ] args ) { int N = 3 ; int D1 [ ] = new int [ ] { 6 , 5 , 4 } ; int D2 [ ] = new int [ ] { 1 , 2 , 3 } ; System . out . print ( minimumDays ( N , D1 , D2 ) ) ; } }