Count minimum number of subsets ( or subsequences ) with consecutive numbers | Java program to find number of subset containing consecutive numbers ; Returns count of subsets with consecutive numbers ; Sort the array so that elements which are consecutive in nature became consecutive in the array . ; Initialize result ; Check if there is beginning of another subset of consecutive number ; Driven Program
import java . util . * ; class GFG { static int numofsubset ( int arr [ ] , int n ) { Arrays . sort ( arr ) ; int count = 1 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( arr [ i ] + 1 != arr [ i + 1 ] ) count ++ ; } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 100 , 56 , 5 , 6 , 102 , 58 , 101 , 57 , 7 , 103 , 59 } ; int n = arr . length ; System . out . println ( numofsubset ( arr , n ) ) ; } }