put the updated consequent number and increment its value ( length )
map . Add ( arr [ i ] , map [ arr [ i ] - 1 ] + 1 ) ; map . Remove ( arr [ i ] - 1 ) ; } else { if ( ! map . ContainsKey ( arr [ i ] ) ) map . Add ( arr [ i ] , 1 ) ; } } int max = int . MinValue ; foreach ( KeyValuePair < int , int > entry in map ) { if ( entry . Value > max ) { max = entry . Value ; } } return max ; }