Longest String With No Three Equal In A Row (Length)
Problem statement
You are given three non-negative integers $a$, $b$, $c$, the available counts of the letters 'a', 'b', and 'c' respectively. Build the longest possible string that uses at most $a$ copies of 'a', at most $b$ copies of 'b', and at most $c$ copies of 'c', subject to the rule that no letter may appear three or more times consecutively (the string must not contain "aaa", "bbb", or "ccc").
Return the length of the longest such string. (The string itself is not unique, but its maximum length is, so you return only the length.)
Write a function with the signature:
def longestNoThreeInARow(a: int, b: int, c: int) -> int:
Constraints:
- $0 \leq a, b, c \leq 100$
Examples:
longestNoThreeInARow(6, 1, 1)->8(for example"aabaacaa"uses 6 a's, 1 b, 1 c, length 8)longestNoThreeInARow(0, 1, 8)->5(for example"ccbcc"; you cannot place all 8 c's without forming"ccc")longestNoThreeInARow(2, 2, 2)->6(for example"aabbcc", all six letters fit)
Show hint
Which single letter could ever force the string to stop early, and why can the others always be placed?
Relevant roles: ML Engineer, Forward Deployed Engineer and AI Engineer.