Length of longest subsequence consisting of distinct adjacent elements | Function that finds the length of longest subsequence having different adjacent elements ; Stores the length of the longest subsequence ; Traverse the array ; If previous and current element are not same ; Increment the count ; Prlet the maximum length ; Driver Code ; Size of Array ; Function Call
function longestSubsequence ( arr , N ) { let count = 1 ; for ( let i = 1 ; i < N ; i ++ ) { if ( arr [ i ] != arr [ i - 1 ] ) { count ++ ; } } document . write ( count ) ; } let arr = [ 7 , 8 , 1 , 2 , 2 , 5 , 5 , 1 ] ; let N = arr . length ; longestSubsequence ( arr , N ) ;