it's basically three cases. if the max color is bigger than the other two combined, the max length is 2 * (sum of smaller two) + 1. for example, 1, 2, 4 gives you bgbgbrb. but if the sum is exactly equal to the largest value, then that last extra char isn't there (so it's just 2 * sum).
if the sum is greater than the max value, i used a cyclic order like rgb, then gbr, then brg. doing it in cycles like this makes sure the char at index i and i+3 are always different because the rotation keeps changing the positions.
in the implementation, i just pick the color with the highest count that doesn't conflict with the char at i-1 or i-3. if there's a conflict, i just give it a rotation and pick the next best one. handles everything in O(N).



