Loading problem...
A sequence is considered well-balanced if it adheres to the following rules:
a.b.c.Given three non-negative integers a, b, and c representing the maximum allowed occurrences of each respective character, construct and return the longest possible well-balanced sequence.
If multiple sequences of maximum length satisfy the conditions, return any one of them. If no valid sequence can be constructed, return an empty string "".
Note: A substring is defined as a contiguous sequence of characters within a string.
a = 1, b = 1, c = 7"ccaccbcc"One valid maximum-length sequence is "ccaccbcc" with length 8. Another valid answer would be "ccbccacc". Notice that 'c' appears 6 times (not exceeding 7), 'a' appears 1 time (not exceeding 1), and 'b' appears 1 time (not exceeding 1). No three consecutive characters are the same.
a = 7, b = 1, c = 0"aabaa"The sequence "aabaa" is the only valid answer with maximum length 5. Since c = 0, the character 'c' cannot appear. We use 5 'a's (out of 7 allowed) and 1 'b' (matching the limit). Using more 'a's would require consecutive 'aaa' which is not allowed.
a = 2, b = 2, c = 1"ababc"The sequence "ababc" uses all available characters: 2 'a's, 2 'b's, and 1 'c', totaling length 5. Other valid arrangements include "abcab", "bacab", etc.
Constraints