<gouthampradhan>string_MonotoneIncreasingDigits_1.java
public int monotoneIncreasingDigits(int N) {
    String s = String.valueOf(N);
    if (s.length() == 1) return N;
    int p = -1;
    int prev = N % 10;
    for (int i = s.length() - 2; i >= 0; i--) {
      int curr = Integer.parseInt(String.valueOf(s.charAt(i)));
      if (curr > prev) {
        p = i;
        prev = curr - 1;
      } else {
        prev = curr;
      }
    }
    if (p == -1) return N;
    StringBuilder result = new StringBuilder();
    for (int i = 0; i < s.length(); i++) {
      if (i == p) {
        int pV = Integer.parseInt(String.valueOf(s.charAt(i)));
        result.append(pV - 1);
        break;
      }
      result.append(String.valueOf(s.charAt(i)));
    }
    for (int i = p + 1; i < s.length(); i++) {
      result.append("9");
    }
    return Integer.parseInt(result.toString());
  }
public int sample_funcname ( int var_0 ) {
  String var_3 = String . valueOf ( var_0 ) ;
  if ( var_3 . length ( ) == 1 ) return var_0 ;
  int var_6 = - 1 ;
  int var_8 = var_0 % 10 ;
  for ( int var_10 = var_3 . length ( ) - 2 ;
  var_10 >= 0 ;
  var_10 -- ) {
    int var_15 = Integer . parseInt ( String . valueOf ( var_3 . charAt ( var_10 ) ) ) ;
    if ( var_15 > var_8 ) {
      var_6 = var_10 ;
      var_8 = var_15 - 1 ;
    }
    else {
      var_8 = var_15 ;
    }
  }
  if ( var_6 == - 1 ) return var_0 ;
  StringBuilder var_17 = new StringBuilder ( ) ;
  for ( int var_10 = 0 ;
  var_10 < var_3 . length ( ) ;
  var_10 ++ ) {
    if ( var_10 == var_6 ) {
      int var_18 = Integer . parseInt ( String . valueOf ( var_3 . charAt ( var_10 ) ) ) ;
      var_17 . append ( var_18 - 1 ) ;
      break ;
    }
    var_17 . append ( String . valueOf ( var_3 . charAt ( var_10 ) ) ) ;
  }
  for ( int var_10 = var_6 + 1 ;
  var_10 < var_3 . length ( ) ;
  var_10 ++ ) {
    var_17 . append ( "9" ) ;
  }
  return Integer . parseInt ( var_17 . toString ( ) ) ;
}
