If number of distinct characters is is greater than k , then move starting point of sliding window forward , until count is k .
if ( distEle > k ) : NEW_LINE INDENT while ( st < end and distEle > k ) : NEW_LINE INDENT if ( cnt [ ord ( str [ st ] ) - ord ( ' a ' ) ] == 1 ) : NEW_LINE INDENT distEle -= 1 NEW_LINE DEDENT cnt [ ord ( str [ st ] ) - ord ( ' a ' ) ] -= 1 NEW_LINE st += 1 NEW_LINE DEDENT DEDENT