Given a sequence of textbook chapters, find the length of the longest subsequence where no two consecutive chapters have the same author, and the authors of the first and last chapters are different.
Explanation: Step-by-step: Given the input ['A', 'B', 'C', 'B', 'A'], we start from the beginning. The first chapter is 'A'. We can choose the next chapter as 'B' because its author is different from 'A'. Then, we can choose 'C' as the next chapter because its author is different from 'B'. However, we cannot choose 'B' as the next chapter because its author is the same as 'C'. Therefore, the longest subsequence where no two consecutive chapters have the same author is ['B', 'C', 'A'] with a length of 3.
Explanation: Step-by-step: Given the input ['A', 'A'], we start from the beginning. The first chapter is 'A'. However, we cannot choose the next chapter as 'A' because its author is the same as the first chapter. Therefore, the longest subsequence where no two consecutive chapters have the same author and the authors of the first and last chapters are different is an empty subsequence with a length of 0.
Master coding challenges related to Strings and solve the [Backup] Optimizing Textbook Sequences problem optimally.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak