Maximize count of planes that can be stopped per second with help of given initial position and speed | Java program for the above approach ; Function to find maximum number of planes that can be stopped from landing ; Stores the times needed for landing for each plane ; Iterate over the arrays ; Stores the time needed for landing of current plane ; Update the value of t ; Append the t in set St ; Return the answer ; Driver Code
import java . util . * ; class GFG { static int maxPlanes ( int [ ] A , int [ ] B ) { Set < Integer > St = new HashSet < > ( ) ; for ( int i = 0 ; i < A . length ; i ++ ) { int t = ( A [ i ] % B [ i ] > 0 ) ? 1 : 0 ; t += ( A [ i ] / B [ i ] ) + t ; St . add ( t ) ; } return St . size ( ) ; } public static void main ( String [ ] args ) { int [ ] A = { 1 , 3 , 5 , 4 , 8 } ; int [ ] B = { 1 , 2 , 2 , 1 , 2 } ; System . out . println ( maxPlanes ( A , B ) ) ; } }