Mid/SeniorGreedyString

String Without AAA or BBB

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

  • s has length a + b and contains exactly a 'a' letters, and exactly b 'b' letters.
  • The substring 'aaa' does not occur in s.
  • The substring 'bbb' does not occur in s.
Example 1
Inputa = 1, b = 2
Output"abb"
"abb", "bab", and "bba" are all correct answers.
Example 2
Inputa = 4, b = 1
Output"aabaa"
The string has exactly four 'a' letters and one 'b' letter without containing 'aaa' or 'bbb'.

Constraints

  • 0 <= a, b <= 100
  • It is guaranteed such an s exists for the given a and b.

Asked at 3 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate