Longest subsequence with different adjacent characters | Function to find the longest Subsequence with different adjacent character ; Length of the string s ; Previously picked character ; If the current character is different from the previous then include this character and update previous character ; Driver Code ; Function call
function longestSubsequence ( s ) { var n = s . length ; var answer = 0 ; var prev = ' ' ; for ( var i = 0 ; i < n ; i ++ ) { if ( prev != s [ i ] ) { prev = s [ i ] ; answer ++ ; } } return answer ; } var str = " " ; document . write ( longestSubsequence ( str ) ) ;