<gouthampradhan>two_pointers_LastSubstringInLexicographicalOrder_1.java
public String lastSubstring(String s) {
    int currAns = 0;
    int candidate = -1;
    int prevIndex = 1;
    for (int i = 1, l = s.length(); i < l; i++) {
      if (candidate != -1) {
        if (s.charAt(i) == s.charAt(prevIndex)) {
          prevIndex++;
        } else if (s.charAt(i) > s.charAt(prevIndex)) {
          if (s.charAt(i) > s.charAt(candidate)) {
            currAns = i;
            candidate = -1;
            prevIndex = currAns + 1;
          } else if (s.charAt(i) == s.charAt(candidate)) {
            currAns = candidate;
            candidate = i;
            prevIndex = currAns + 1;
          } else {
            currAns = candidate;
            candidate = -1;
            prevIndex = currAns + 1;
          }
        } else {
          candidate = -1;
          prevIndex = currAns + 1;
        }
      } else {
        if (s.charAt(i) > s.charAt(currAns)) {
          currAns = i;
          candidate = -1;
          prevIndex = currAns + 1;
        } else if (s.charAt(i) == s.charAt(currAns)) {
          candidate = i;
        }
      }
    }
    return s.substring(currAns);
  }
public String var_0 ( String var_2 ) {
  int var_4 = 0 ;
  int var_6 = - 1 ;
  int var_7 = 1 ;
  for ( int var_8 = 1 , var_10 = var_2 . length ( ) ;
  var_8 < var_10 ;
  var_8 ++ ) {
    if ( var_6 != - 1 ) {
      if ( var_2 . charAt ( var_8 ) == var_2 . charAt ( var_7 ) ) {
        var_7 ++ ;
      }
      else if ( var_2 . charAt ( var_8 ) > var_2 . charAt ( var_7 ) ) {
        if ( var_2 . charAt ( var_8 ) > var_2 . charAt ( var_6 ) ) {
          var_4 = var_8 ;
          var_6 = - 1 ;
          var_7 = var_4 + 1 ;
        }
        else if ( var_2 . charAt ( var_8 ) == var_2 . charAt ( var_6 ) ) {
          var_4 = var_6 ;
          var_6 = var_8 ;
          var_7 = var_4 + 1 ;
        }
        else {
          var_4 = var_6 ;
          var_6 = - 1 ;
          var_7 = var_4 + 1 ;
        }
      }
      else {
        var_6 = - 1 ;
        var_7 = var_4 + 1 ;
      }
    }
    else {
      if ( var_2 . charAt ( var_8 ) > var_2 . charAt ( var_4 ) ) {
        var_4 = var_8 ;
        var_6 = - 1 ;
        var_7 = var_4 + 1 ;
      }
      else if ( var_2 . charAt ( var_8 ) == var_2 . charAt ( var_4 ) ) {
        var_6 = var_8 ;
      }
    }
  }
  return var_2 . substring ( var_4 ) ;
}
