Given a string representing the order of ingredients, return the length of the longest subsequence where ingredients alternate between 'S' and 'T'.
Explanation: Step-by-step: with input SST, we start with 'S', then 'T', then 'S', giving output 3. The longest subsequence where ingredients alternate between 'S' and 'T' is 'S-T-S'.
Explanation: Step-by-step: with input TSTT, we start with 'T', then 'S', then 'T', but the last character 'T' does not match 'S', giving output 2. The longest subsequence where ingredients alternate between 'S' and 'T' is 'T-S-T'.
Master coding challenges related to Strings and solve the [Backup] Recipe Validator problem optimally.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak