comefrom: <doocs>0556.Next Greater Element III_1.py
code: def nextGreaterElement( n: int) -> int:
      cs = list(str(n))
      n = len(cs)
      i, j = n - 2, n - 1
      while i >= 0 and cs[i] >= cs[i + 1]:
          i -= 1
      if i < 0:
          return -1
      while cs[i] >= cs[j]:
          j -= 1
      cs[i], cs[j] = cs[j], cs[i]
      cs[i + 1 :] = cs[i + 1 :][::-1]
      ans = int(''.join(cs))
      return -1 if ans > 2**31 - 1 else ans
masked: def sample_funcname ( var_0 : int ) -> int :
      var_4 = list ( str ( var_0 ) )
      var_0 = len ( var_4 )
      var_7 , var_9 = var_0 - 2 , var_0 - 1
      while var_7 >= 0 and var_4 [ var_7 ] >= var_4 [ var_7 + 1 ] :
          var_7 -= 1
      if var_7 < 0 :
          return - 1
      while var_4 [ var_7 ] >= var_4 [ var_9 ] :
          var_9 -= 1
      var_4 [ var_7 ] , var_4 [ var_9 ] = var_4 [ var_9 ] , var_4 [ var_7 ]
      var_4 [ var_7 + 1 : ] = var_4 [ var_7 + 1 : ] [ : : - 1 ]
      var_13 = int ( ''.join ( var_4 ) )
      return - 1 if var_13 > 2 ** 31 - 1 else var_13
  