Count minimum number of subsets ( or subsequences ) with consecutive numbers | C # 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
using System ; class GFG { static int numofsubset ( int [ ] arr , int n ) { Array . 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 ( ) { int [ ] arr = { 100 , 56 , 5 , 6 , 102 , 58 , 101 , 57 , 7 , 103 , 59 } ; int n = arr . Length ; Console . WriteLine ( numofsubset ( arr , n ) ) ; } }