comefrom: <awangdev>340. Longest Substring with At Most K Distinct Characters_3.java
code: public int lengthOfLongestSubstringKDistinct(String s, int k) {
          if (s == null || s.length() == 0) return 0;
          int n = s.length();
          Map<Character, Integer> lastOccurMap = new LinkedHashMap<>(k + 1);
          int left = 0, right = 0, max = 0;
  
          while (right < n) {
              char c = s.charAt(right);
              if (lastOccurMap.containsKey(c)) lastOccurMap.remove(c);
              lastOccurMap.put(c, right++);
              
              if (lastOccurMap.size() > k) { 
                  Map.Entry<Character, Integer> leftMost = lastOccurMap.entrySet().iterator().next();
                  lastOccurMap.remove(leftMost.getKey());
                  left = leftMost.getValue() + 1;
              }
              max = Math.max(max, right - left);
          }
  
          return max;
      }
masked: public int sample_funcname ( String var_0 , int var_1 ) {
    if ( var_0 == null || var_0 . length ( ) == 0 ) return 0 ;
    int var_2 = var_0 . length ( ) ;
    Map < Character , Integer > var_3 = new LinkedHashMap < > ( var_1 + 1 ) ;
    int var_4 = 0 , var_5 = 0 , max = 0 ;
    while ( var_5 < var_2 ) {
      char var_6 = var_0 . charAt ( var_5 ) ;
      if ( var_3 . containsKey ( var_6 ) ) var_3 . remove ( var_6 ) ;
      var_3 . put ( var_6 , var_5 ++ ) ;
      if ( var_3 . size ( ) > var_1 ) {
        Map . Entry < Character , Integer > var_7 = var_3 . entrySet ( ) . iterator ( ) . next ( ) ;
        var_3 . remove ( var_7 . getKey ( ) ) ;
        var_4 = var_7 . getValue ( ) + 1 ;
      }
      max = Math . max ( max , var_5 - var_4 ) ;
    }
    return max ;
  }
  