<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> class Solution : <EOL> def lengthOfLongestSubstringKDistinct ( self , s , k ) : <EOL> """<STR_LIT>""" <EOL> if len ( s ) < <NUM_LIT:1> or k < <NUM_LIT:1> : <EOL> return <NUM_LIT:0> <EOL> cnt = { } <EOL> b = <NUM_LIT:0> <EOL> e = <NUM_LIT:1> <EOL> cnt [ s [ b ] ] = <NUM_LIT:1> <EOL> maxa = <NUM_LIT:1> <EOL> while e < len ( s ) : <EOL> if s [ e ] not in cnt : <EOL> cnt [ s [ e ] ] = <NUM_LIT:0> <EOL> cnt [ s [ e ] ] += <NUM_LIT:1> <EOL> e += <NUM_LIT:1> <EOL> while len ( cnt ) > k : <EOL> cnt [ s [ b ] ] -= <NUM_LIT:1> <EOL> if cnt [ s [ b ] ] <= <NUM_LIT:0> : <EOL> del cnt [ s [ b ] ] <EOL> b += <NUM_LIT:1> <EOL> maxa = max ( maxa , e - b ) <EOL> return maxa <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> assert Solution ( ) . lengthOfLongestSubstringKDistinct ( "<STR_LIT>" , <NUM_LIT:3> ) == <NUM_LIT:4> </s>
