Given a string representing a sequence of transmission signals, find the length of the longest substring where the signals appear in an alternating sequence of 3 distinct signal types (denoted by 'A', 'B', and 'C'), with each signal type appearing only once in the sequence and the sequence starting and ending with the same signal type.
Explanation: Step-by-step: with input ABCBC, we do A then B then C then B then C, but this sequence does not meet the condition of each signal type appearing only once. However, if we consider the sequence ABCBCA, it meets the condition of each signal type appearing only once and the sequence starting and ending with the same signal type. Therefore, the longest substring is ABCBCA, which has a length of 6. However, we need to find the longest substring that meets the condition, which is ABCBCA without the last A, giving a length of 5.
Explanation: Step-by-step: with input ABCB, we do A then B then C then B, but this sequence does not meet the condition of each signal type appearing only once. Therefore, the longest substring that meets the condition is ABC, which has a length of 3. However, we can extend this sequence to ABCB, which has a length of 4.
Master coding challenges related to Strings and solve the [Backup] Galactic Transmission Protocol problem optimally.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak