Maximize count of nodes disconnected from all other nodes in a Graph | Java implementation of the above approach ; Function which returns the maximum number of isolated nodes ; Used nodes ; Remaining edges ; Count nodes used ; If given edges are non - zero ; Driver Code ; Given N and E ; Function call
import java . util . * ; class GFG { static int maxDisconnected ( int N , int E ) { int curr = 1 ; int rem = E ; while ( rem > 0 ) { rem = rem - Math . min ( curr , rem ) ; curr ++ ; } if ( curr > 1 ) { return N - curr ; } else { return N ; } } public static void main ( String [ ] args ) { int N = 5 , E = 1 ; System . out . print ( maxDisconnected ( N , E ) ) ; } }