Ctrl K

Two-Letter Tiles, No Triples

Medium
A box holds three kinds of two-letter tiles: aa tiles "AA", bb tiles "BB" and ab tiles "AB". Tiles are laid out in a row in any order and cannot be flipped. You may use any subset of them, from all to none. The resulting string must not contain three equal letters in a row ("AAA" or "BBB"). Return the maximum possible length of the string.
Example 1
aa=1, bb=1, ab=1 → 6

All three tiles fit: "AB" + "AA" + "BB" = "ABAABB", length 6, with no three equal letters in a row.

Example 2
aa=4, bb=1, ab=2 → 10

"AA" tiles must alternate with "BB", and there is only one "BB", so at most two "AA" fit. For example "AB" + "AB" + "AA" + "BB" + "AA" = "ABABAABBAA", length 10.

Example 3
aa=3, bb=3, ab=5 → 22
Constraints
  • 1 ≤ aa, bb, ab ≤ 50
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsLast Viewer in the Right Seat MediumTake From Any Pile MediumTerms Sharing a Last Digit MediumChunks With a Common Divisor MediumDivisor Subtraction Duel Easy
loading Python…
Input
aa=1, bb=1, ab=1
Expected
6

Run checks the first 3 tests in your browser. Submit checks all 88 tests on the server, hidden ones included.