195. String Without AAA or BBB

EasyStringString

Given two integers a and b, return any string s such that:

- s has length a+b and contains exactly a 'a's and b 'b's.
- The string does not contain 'aaa' or 'bbb' as a substring.

Input is two comma-separated integers a and b. It is guaranteed that a valid answer exists.

Input: Two comma-separated integers: a (count of 'a') and b (count of 'b').

Output: A valid string (any correct answer is accepted).

Examples

Example 1
Input: 1,2
Output: abb
Explanation: 1 'a' and 2 'b's; 'bbb' absent.
Example 2
Input: 4,1
Output: aabaa
Explanation: 4 'a's and 1 'b'; 'aaa' absent.
Example 3
Input: 2,2
Output: aabb
Explanation: 2 each; no triple run.

Constraints

Asked by

GoogleAmazon
Solve this problem in the editor →