Count minimum number of subsets ( or subsequences ) with 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
function numofsubset ( arr , n ) { arr . sort ( ( a , b ) => a - b ) ; var count = 1 ; for ( i = 0 ; i < n - 1 ; i ++ ) { if ( arr [ i ] + 1 != arr [ i + 1 ] ) count ++ ; } return count ; } var arr = [ 100 , 56 , 5 , 6 , 102 , 58 , 101 , 57 , 7 , 103 , 59 ] ; var n = arr . length ; document . write ( numofsubset ( arr , n ) ) ;