<gouthampradhan>binary_search_MinimumWindowSubsequence_1.java
public String minWindow(String S, String T) {
    if (T.isEmpty() || S.isEmpty()) return "";
    Map<Character, TreeSet<Integer>> charMap = new HashMap<>();
    for (int i = 0, l = S.length(); i < l; i++) {
      char c = S.charAt(i);
      charMap.putIfAbsent(c, new TreeSet<>());
      charMap.get(c).add(i);
    }
    int min = Integer.MAX_VALUE;
    int start = -1, end;
    int ansStart = -1, ansEnd = -1;
    boolean finished = false;
    while (true) {
      int index = start;
      end = -1;
      for (int i = 0, l = T.length(); i < l; i++) {
        char c = T.charAt(i);
        if (!charMap.containsKey(c)) {
          return "";
        } else {
          TreeSet<Integer> indicies = charMap.get(c);
          Integer found = indicies.higher(index);
          if (found == null) {
            finished = true;
            break;
          } else {
            index = found;
            if (i == 0) {
              start = index;
            }
            if (i == l - 1) {
              end = index;
            }
          }
        }
      }
      if (start != -1 && end != -1) {
        if ((end - start) < min) {
          min = end - start;
          ansStart = start;
          ansEnd = end;
        }
      }
      if (finished) return ansStart == -1 ? "" : S.substring(ansStart, ansEnd + 1);
    }
  }
public String var_0 ( String var_2 , String var_3 ) {
  if ( var_3 . isEmpty ( ) || var_2 . isEmpty ( ) ) return "" ;
  Map < Character , TreeSet < Integer >> var_11 = new HashMap < > ( ) ;
  for ( int var_13 = 0 , var_15 = var_2 . length ( ) ;
  var_13 < var_15 ;
  var_13 ++ ) {
    char var_17 = var_2 . charAt ( var_13 ) ;
    var_11 . putIfAbsent ( var_17 , new TreeSet < > ( ) ) ;
    var_11 . get ( var_17 ) . add ( var_13 ) ;
  }
  int var_22 = Integer . MAX_VALUE ;
  int var_24 = - 1 , var_25 ;
  int var_26 = - 1 , var_27 = - 1 ;
  boolean var_35 = false ;
  while ( true ) {
    int var_29 = var_24 ;
    var_25 = - 1 ;
    for ( int var_13 = 0 , var_15 = var_3 . length ( ) ;
    var_13 < var_15 ;
    var_13 ++ ) {
      char var_17 = var_3 . charAt ( var_13 ) ;
      if ( ! var_11 . containsKey ( var_17 ) ) {
        return "" ;
      }
      else {
        TreeSet < Integer > var_31 = var_11 . get ( var_17 ) ;
        Integer var_33 = var_31 . higher ( var_29 ) ;
        if ( var_33 == null ) {
          var_35 = true ;
          break ;
        }
        else {
          var_29 = var_33 ;
          if ( var_13 == 0 ) {
            var_24 = var_29 ;
          }
          if ( var_13 == var_15 - 1 ) {
            var_25 = var_29 ;
          }
        }
      }
    }
    if ( var_24 != - 1 && var_25 != - 1 ) {
      if ( ( var_25 - var_24 ) < var_22 ) {
        var_22 = var_25 - var_24 ;
        var_26 = var_24 ;
        var_27 = var_25 ;
      }
    }
    if ( var_35 ) return var_26 == - 1 ? "" : var_2 . substring ( var_26 , var_27 + 1 ) ;
  }
}
