Maximum distinct lowercase alphabets between two uppercase | PHP 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
< ? php $ MAX_CHAR = 26 ; function maxLower ( $ str ) { global $ MAX_CHAR ; $ n = strlen ( $ str ) ; $ i = 0 ; for ( ; $ i < $ n ; $ i ++ ) { if ( $ str [ $ i ] >= ' A ' && $ str [ $ i ] <= ' Z ' ) { $ i ++ ; break ; } } $ maxCount = 0 ; $ count = array_fill ( 0 , $ MAX_CHAR , NULL ) ; for ( ; $ i < $ n ; $ i ++ ) { if ( $ str [ $ i ] >= ' A ' && $ str [ $ i ] <= ' Z ' ) { $ currCount = 0 ; for ( $ j = 0 ; $ j < $ MAX_CHAR ; $ j ++ ) if ( $ count [ $ j ] > 0 ) $ currCount ++ ; $ maxCount = max ( $ maxCount , $ currCount ) ; $ count = array_fill ( 0 , $ MAX_CHAR , NULL ) ; } if ( $ str [ $ i ] >= ' a ' && $ str [ $ i ] <= ' z ' ) $ count [ ord ( $ str [ $ i ] ) - ord ( ' a ' ) ] ++ ; } return $ maxCount ; } $ str = " zACaAbbaazzC " ; echo maxLower ( $ str ) ; ? >