<awangdev>340. Longest Substring with At Most K Distinct Characters_3.java
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;
    }
public int sample_funcname ( String var_1 , int var_2 ) {
  if ( var_1 == null || var_1 . length ( ) == 0 ) return 0 ;
  int var_6 = var_1 . length ( ) ;
  Map < Character , Integer > var_12 = new LinkedHashMap < > ( var_2 + 1 ) ;
  int var_13 = 0 , var_14 = 0 , max = 0 ;
  while ( var_14 < var_6 ) {
    char var_17 = var_1 . charAt ( var_14 ) ;
    if ( var_12 . containsKey ( var_17 ) ) var_12 . remove ( var_17 ) ;
    var_12 . put ( var_17 , var_14 ++ ) ;
    if ( var_12 . size ( ) > var_2 ) {
      Map . Entry < Character , Integer > var_26 = var_12 . entrySet ( ) . iterator ( ) . next ( ) ;
      var_12 . remove ( var_26 . getKey ( ) ) ;
      var_13 = var_26 . getValue ( ) + 1 ;
    }
    max = Math . max ( max , var_14 - var_13 ) ;
  }
  return max ;
}
