comefrom: <awangdev>340. Longest Substring with At Most K Distinct Characters_1.java
code: public int lengthOfLongestSubstringKDistinct(String s, int k) {
          if (s == null)  return 0;
          int left = 0, right = 0, max = 0, n = s.length();
          Map<Character, Integer> freq = new HashMap<>();
  
          while (right < n) {
              char head = s.charAt(right++);
              freq.put(head, freq.getOrDefault(head, 0) + 1);
              
              if (freq.size() <= k) max = Math.max(max, right - left);
              
              if (freq.size() > k) {
                  char tail = s.charAt(left++);
                  freq.put(tail, freq.get(tail) - 1);
                  if (freq.get(tail) == 0) freq.remove(tail);
              }
          }
          
          return max;
      }
masked: public int sample_funcname ( String var_0 , int var_1 ) {
    if ( var_0 == null ) return 0 ;
    int var_2 = 0 , var_3 = 0 , max = 0 , var_4 = var_0 . length ( ) ;
    Map < Character , Integer > var_5 = new HashMap < > ( ) ;
    while ( var_3 < var_4 ) {
      char var_6 = var_0 . charAt ( var_3 ++ ) ;
      var_5 . put ( var_6 , var_5 . getOrDefault ( var_6 , 0 ) + 1 ) ;
      if ( var_5 . size ( ) <= var_1 ) max = Math . max ( max , var_3 - var_2 ) ;
      if ( var_5 . size ( ) > var_1 ) {
        char var_7 = var_0 . charAt ( var_2 ++ ) ;
        var_5 . put ( var_7 , var_5 . get ( var_7 ) - 1 ) ;
        if ( var_5 . get ( var_7 ) == 0 ) var_5 . remove ( var_7 ) ;
      }
    }
    return max ;
  }
  