ReadingBooks
SRM 404 · 2008-06-05 · by boba5551
Problem Statement
There are some books, each consisting of exactly three parts: introduction, story and edification. There is a reader who goes through the books and reads various parts. Each time he finishes reading a part, he adds the name of the part to the end of a list. He may read zero or more parts from each book, and he can read them in any order, but he cannot read each part more than once. Whenever he starts reading a new book, he can no longer go back and read any parts of books he has looked at previously.
You are given a
Constraints
- readParts will contain between 1 and 50 elements, inclusive.
- Each element of readParts will be "introduction", "story" or "edification" (quotes for clarity).
{"edification", "story", "introduction", "edification", "introduction", "story", "edification"}
Returns: 2
{"introduction", "story", "introduction", "edification"}
Returns: 1
It is possible that the reader has read the introduction from the first book and all 3 parts from the second one. Of course, it is also possible that he has read one part from four different books, but we are interested in the maximal number of books for which all 3 parts have been read.
{"story", "edification", "introduction", "story", "edification", "introduction", "introduction", "story", "edification", "introduction"}
Returns: 3
{"introduction", "introduction", "introduction", "story", "story", "story", "edification", "edification", "edification"}
Returns: 0
{"introduction", "story", "edification", "introduction", "story", "edification"}
Returns: 2
Two books have been read in their entirety.
Submissions are judged against all 86 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class ReadingBooks with a public method int countBooks(vector<string> readParts) · 86 test cases · 2 s / 256 MB per case