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_2 : int ) -> str :
      var_6 = [ 0 ] * 26
      for var_7 in var_0 :
          var_6 [ ord ( var_7 ) - ord ( 'a' ) ] += 1
      var_11 = [ ]
      for var_14 in range ( 25 , - 1 , - 1 ) :
          var_15 = var_14 - 1
          while 1 :
              for var_17 in range ( min ( var_2 , var_6 [ var_14 ] ) ) :
                  var_6 [ var_14 ] -= 1
                  var_11.append ( chr ( ord ( 'a' ) + var_14 ) )
              if var_6 [ var_14 ] == 0 :
                  break
              while var_15 >= 0 and var_6 [ var_15 ] == 0 :
                  var_15 -= 1
              if var_15 < 0 :
                  break
              var_6 [ var_15 ] -= 1
              var_11.append ( chr ( ord ( 'a' ) + var_15 ) )
      return ''.join ( var_11 )
  