comefrom: <doocs>2182.Construct String With Repeat Limit_1.py
code: def repeatLimitedString( s: str, repeatLimit: int) -> str:
      cnt = [0] * 26
      for c in s:
          cnt[ord(c) - ord('a')] += 1
      ans = []
      for i in range(25, -1, -1):
          j = i - 1
          while 1:
              for _ in range(min(repeatLimit, cnt[i])):
                  cnt[i] -= 1
                  ans.append(chr(ord('a') + i))
              if cnt[i] == 0:
                  break
              while j >= 0 and cnt[j] == 0:
                  j -= 1
              if j < 0:
                  break
              cnt[j] -= 1
              ans.append(chr(ord('a') + j))
      return ''.join(ans)
masked: def sample_funcname ( var_0 : str , var_1 : int ) -> str :
      var_2 = [ 0 ] * 26
      for var_3 in var_0 :
          var_2 [ ord ( var_3 ) - ord ( 'a' ) ] += 1
      var_4 = [ ]
      for var_5 in range ( 25 , - 1 , - 1 ) :
          var_6 = var_5 - 1
          while 1 :
              for var_7 in range ( min ( var_1 , var_2 [ var_5 ] ) ) :
                  var_2 [ var_5 ] -= 1
                  var_4.append ( chr ( ord ( 'a' ) + var_5 ) )
              if var_2 [ var_5 ] == 0 :
                  break
              while var_6 >= 0 and var_2 [ var_6 ] == 0 :
                  var_6 -= 1
              if var_6 < 0 :
                  break
              var_2 [ var_6 ] -= 1
              var_4.append ( chr ( ord ( 'a' ) + var_6 ) )
      return ''.join ( var_4 )
  