Medium · Strings

Longest Happy String

Given three non-negative integers a, b and c, return the longest string made of the letters 'a', 'b' and 'c' that uses at most a 'a's, b 'b's and c 'c's and never has three equal letters in a row; if several strings are longest, return any one of them.

Examples

Example 1

a=1 b=1 c=7

Output: "ccaccbcc" (len 8)

Example 2

a=2 b=2 c=1

Output: "abbac" (len 5)

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Strings problems