The Construct the Longest New String interview question is a combinatorial optimization problem. You are given three types of two-letter strings: "AA", "BB", and "AB". You have x of "AA", y of "BB", and z of "AB". You need to concatenate these strings to form the longest possible sequence such that the resulting string does not contain "AAA" or "BBB" as a substring.
Companies like Microsoft ask the Construct the Longest New String coding problem to test a candidate's ability to simplify a seemingly complex state-based problem. While it can be modeled with Dynamic Programming, the optimal solution is actually a mathematical "Brainteaser." It evaluates if you can identify the governing constraints (like the fact that "AA" must be followed by "BB", and vice-versa) to find a greedy or closed-form solution.
This follows the Brainteaser, Math, Greedy interview pattern.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Airplane Seat Assignment Probability | Medium | Solve | |
| Divisor Game | Easy | Solve | |
| Smallest Number With Given Digit Product | Medium | Solve | |
| 4 Keys Keyboard | Medium | Solve | |
| Broken Calculator | Medium | Solve |