Please give me approach as well as short and sweet code; remember short and sweet
Amazon is looking to develop a new labeling system in the fulfillment centers. New labels will be devised from the original string labels. Given the original string label, construct a new string by rearranging the original string and deleting characters as needed. Return the alphabetically-largest string that can be constructed respecting the limit as to how many consecutive characters can be the same (represented by k).
“Alphabetically-largest” is defined in reverse alphabetical order (e.g., b is “larger” than a, c is “larger” than b, etc.) from left to right (e.g., “ba” is larger than “ab”).
Write an algorithm to return the alphabetically-largest string that can be constructed respecting the above limits.
The input to the function/method consists of two arguments:
originalLabel, a string representing the original string label;
charlimit, an integer representing the maximum number of identical consecutive characters the new string can have (k).
Return a string representing the alphabetically largest string that can be constructed that has no more than k identical consecutive characters.
1 <= len <= 10^5; where len represents the length of originalLabel
1 <= charlimit <= 10^3
The string originalLabel contains only lowercase English letters.
originalLabel = baccc
charLimit = 2
The largest string, alphabetically, is ‘cccba’ but it is not allowed because it uses the character’s more than 2 times consecutively. Therefore, the answer is ‘ccbca’.
Thanks in advance!!!