Maximum distinct lowercase alphabets between two uppercase | Javascript Program to find maximum lowercase alphabets present between two uppercase alphabets ; Function which computes the maximum number of distinct lowercase alphabets between two uppercase alphabets ; Ignoring lowercase characters in the beginning . ; We start from next of first capital letter and traverse through remaining character . ; If character is in uppercase , ; Count all distinct lower case characters ; Update maximum count ; Reset count array ; If character is in lowercase ; Driver code
let MAX_CHAR = 26 ; function maxLower ( str ) { let n = str . length ; let i = 0 ; for ( ; i < n ; i ++ ) { if ( str [ i ] >= ' ' && str [ i ] <= ' ' ) { i ++ ; break ; } } let maxCount = 0 ; let count = new Array ( MAX_CHAR ) ; for ( ; i < n ; i ++ ) { if ( str [ i ] >= ' ' && str [ i ] <= ' ' ) { let currCount = 0 ; for ( let j = 0 ; j < MAX_CHAR ; j ++ ) { if ( count [ j ] > 0 ) { currCount ++ ; } } maxCount = Math . max ( maxCount , currCount ) ; for ( let i = 0 ; i < count . length ; i ++ ) { count [ i ] = 0 ; } } if ( str [ i ] >= ' ' && str [ i ] <= ' ' ) { count [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; } } return maxCount ; } let str = " " ; document . write ( maxLower ( str ) ) ;