Given two integers a
and b
, return any string s
such that:
s
has lengtha + b
and contains exactlya
'a'
letters, and exactlyb
'b'
letters,- The substring
'aaa'
does not occur ins
, and - The substring
'bbb'
does not occur ins
.
Input: a = 1, b = 2 Output: "abb" Explanation: "abb", "bab" and "bba" are all correct answers.
Input: a = 4, b = 1 Output: "aabaa"
0 <= a, b <= 100
- It is guaranteed such an
s
exists for the givena
andb
.
# @param {Integer} a
# @param {Integer} b
# @return {String}
def str_without3a3b(a, b)
more_ch, less_ch = a > b ? %w[a b] : %w[b a]
more_cnt = [a, b].max
less_cnt = [a, b].min
part0 = more_ch * 2 + less_ch
part1 = more_ch + less_ch
part2 = more_ch
x = [more_cnt - less_cnt, less_cnt].min
y = [2 * less_cnt - more_cnt, 0].max
z = [more_cnt - 2 * less_cnt, 0].max
part0 * x + part1 * y + part2 * z
end