Company: Amex_23july
Difficulty: medium
Construct Longest String Without Forbidden Substrings Problem Description You have three kinds of two-letter strings: AA strings - there are AA of them, AB strings - there are AB of them, BB strings - there are BB of them. Choose some of these strings (each available string may be used at most once, and you do not have to use all of them) and join them end to end, in any order you like, to form one long string. The joined string must not contain "AAA" or "BBB" as a substring. This applies to the whole joined string, including letters that meet across the boundary between two strings. (inferred - each two-letter string is used whole, exactly as written; it cannot be split or reversed.) For example, with AA = 5 , AB = 0 and BB = 2 , you can take both "BB" strings and three of the "AA" strings and join them as AA-BB-AA-BB-AA , which gives "AABBAABBAA" . Adding a fourth "AA" anywhere would put two "AA" strings next to each other and create "AAA" . Your task is to find the length of the lon