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 ; Driver Code
< ? php function numofsubset ( $ arr , $ n ) { sort ( $ arr ) ; $ count = 1 ; for ( $ i = 0 ; $ i < $ n - 1 ; $ i ++ ) { if ( $ arr [ $ i ] + 1 != $ arr [ $ i + 1 ] ) $ count ++ ; } return $ count ; } $ arr = array ( 100 , 56 , 5 , 6 , 102 , 58 , 101 , 57 , 7 , 103 , 59 ) ; $ n = sizeof ( $ arr ) ; echo numofsubset ( $ arr , $ n ) ; ? >