Minimum matches the team needs to win to qualify | Java implementation of the approach ; Function to return the minimum number of matches to win to qualify for next round ; Do a binary search to find ; Find mid element ; Check for condition to qualify for next round ; Driver Code
import java . io . * ; class GFG { static int findMinimum ( int x , int y ) { int low = 0 , high = y ; while ( low <= high ) { int mid = ( low + high ) >> 1 ; if ( ( mid * 2 + ( y - mid ) ) >= x ) high = mid - 1 ; else low = mid + 1 ; } return low ; } public static void main ( String [ ] args ) { int x = 6 , y = 5 ; System . out . println ( findMinimum ( x , y ) ) ; } }