<gouthampradhan>greedy_PartitionLabels_1.java
public List<Integer> partitionLabels(String S) {
    Map<Character, Integer> map = new HashMap<>();
    for (int i = 0; i < S.length(); i++) {
      char c = S.charAt(i);
      map.putIfAbsent(c, i);
      map.remove(c);
      map.put(c, i);
    }
    char start = S.charAt(0);
    int currMax = map.get(start);
    int startIndex = 0;
    List<Integer> list = new ArrayList<>();
    while (true) {
      int i = startIndex;
      for (; i <= currMax; i++) {
        char c = S.charAt(i);
        int pos = map.get(c);
        currMax = Math.max(currMax, pos);
      }
      if (i > currMax && i < S.length()) {
        list.add(i - startIndex);
        startIndex = i;
        currMax = map.get(S.charAt(i));
      } else {
        if (i == S.length()) {
          list.add(i - startIndex);
          break;
        }
      }
    }
    return list;
  }
public List < Integer > var_1 ( String var_3 ) {
  Map < Character , Integer > var_7 = new HashMap < > ( ) ;
  for ( int var_9 = 0 ;
  var_9 < var_3 . length ( ) ;
  var_9 ++ ) {
    char var_12 = var_3 . charAt ( var_9 ) ;
    var_7 . putIfAbsent ( var_12 , var_9 ) ;
    var_7 . remove ( var_12 ) ;
    var_7 . put ( var_12 , var_9 ) ;
  }
  char var_16 = var_3 . charAt ( 0 ) ;
  int var_18 = var_7 . get ( var_16 ) ;
  int var_19 = 0 ;
  List < Integer > var_22 = new ArrayList < > ( ) ;
  while ( true ) {
    int var_9 = var_19 ;
    for ( ;
    var_9 <= var_18 ;
    var_9 ++ ) {
      char var_12 = var_3 . charAt ( var_9 ) ;
      int var_23 = var_7 . get ( var_12 ) ;
      var_18 = Math . max ( var_18 , var_23 ) ;
    }
    if ( var_9 > var_18 && var_9 < var_3 . length ( ) ) {
      var_22 . add ( var_9 - var_19 ) ;
      var_19 = var_9 ;
      var_18 = var_7 . get ( var_3 . charAt ( var_9 ) ) ;
    }
    else {
      if ( var_9 == var_3 . length ( ) ) {
        var_22 . add ( var_9 - var_19 ) ;
        break ;
      }
    }
  }
  return var_22 ;
}
