Largest increasing subsequence of consecutive integers | C # implementation of longest continuous increasing subsequence ; Function for LIS ; Initialize result ; iterate through array and find end index of LIS and its Size ; print LIS size ; print LIS after setting start element ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void findLIS ( int [ ] A , int n ) { Dictionary < int , int > hash = new Dictionary < int , int > ( ) ; int LIS_size = 1 ; int LIS_index = 0 ; hash . Add ( A [ 0 ] , 1 ) ; for ( int i = 1 ; i < n ; i ++ ) { if ( hash . ContainsKey ( A [ i ] - 1 ) ) { var val = hash [ A [ i ] - 1 ] ; hash . Remove ( A [ i ] ) ; hash . Add ( A [ i ] , val + 1 ) ; } else { hash . Add ( A [ i ] , 1 ) ; } if ( LIS_size < hash [ A [ i ] ] ) { LIS_size = hash [ A [ i ] ] ; LIS_index = A [ i ] ; } } Console . WriteLine ( " LIS _ size ▁ = ▁ " + LIS_size ) ; Console . Write ( " LIS ▁ : ▁ " ) ; int start = LIS_index - LIS_size + 1 ; while ( start <= LIS_index ) { Console . Write ( start + " ▁ " ) ; start ++ ; } } public static void Main ( String [ ] args ) { int [ ] A = { 2 , 5 , 3 , 7 , 4 , 8 , 5 , 13 , 6 } ; int n = A . Length ; findLIS ( A , n ) ; } }