Maximum distinct lowercase alphabets between two uppercase | Java 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 , ; Update maximum count if lowercase character before this is more . ; clear the set ; If character is in lowercase ; Driver Code
import java . util . * ; class GFG { static int maxLower ( char [ ] str ) { int n = str . length ; int i = 0 ; for ( ; i < n ; i ++ ) { if ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) { i ++ ; break ; } } int maxCount = 0 ; HashSet < Integer > s = new HashSet < Integer > ( ) ; for ( ; i < n ; i ++ ) { if ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) { maxCount = Math . max ( maxCount , ( int ) s . size ( ) ) ; s . clear ( ) ; } if ( str [ i ] >= ' a ' && str [ i ] <= ' z ' ) s . add ( ( int ) str [ i ] ) ; } return maxCount ; } public static void main ( String args [ ] ) { String str = " zACaAbbaazzC " ; System . out . println ( maxLower ( str . toCharArray ( ) ) ) ; } }