Length of longest increasing subsequence in a string | Function to find length of longest increasing subsequence in a string ; Stores at every i - th index , the length of the longest increasing subsequence ending with character i ; Size of string ; Stores the length of LIS ; Iterate over each character of the string ; Store position of the current character ; Stores the length of LIS ending with current character ; Check for all characters less then current character ; Include current character ; Update length of longest increasing subsequence ; Updating LIS for current character ; Return the length of LIS ; Driver Code
function lisOtimised ( s ) { let dp = new Array ( 30 ) . fill ( 0 ) ; let N = s . length ; let lis = Number . MIN_VALUE ; for ( let i = 0 ; i < N ; i ++ ) { let val = s . charCodeAt ( i ) - ' ' . charCodeAt ( 0 ) ; let curr = 0 ; for ( let j = 0 ; j < val ; j ++ ) { curr = Math . max ( curr , dp [ j ] ) ; } curr ++ ; lis = Math . max ( lis , curr ) ; dp [ val ] = Math . max ( dp [ val ] , curr ) ; } return lis ; } let s = " " ; document . write ( lisOtimised ( s ) ) ;