Minimize total time taken by two persons to visit N cities such that none of them meet | Java program for the above approach ; Function to find the minimum time to visit all the cities such that both the person never meets ; Initialize sum as 0 ; Find the maximum element ; Traverse the array ; Increment sum by arr [ i ] ; Print maximum of 2 * T and sum ; Driver code ; Function Call
import java . util . * ; class GFG { static void minimumTime ( int [ ] arr , int n ) { int sum = 0 ; int T = Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } System . out . println ( Math . max ( 2 * T , sum ) ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 8 , 3 } ; int N = arr . length ; minimumTime ( arr , N ) ; } }