Connection Status:
Competition Arena > ReadingBooks
SRM 404 · 2008-06-05 · by boba5551 · Greedy, Simple Search, Iteration
Class Name: ReadingBooks
Return Type: int
Method Name: countBooks
Arg Types: (vector<string>)
Problem Statement

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 String[] readParts containing the list created by the reader. Each element of readParts is "introduction", "story" or "edification" (quotes for clarity). Return the maximum possible number of books for which the reader has read all three parts.

Constraints

  • readParts will contain between 1 and 50 elements, inclusive.
  • Each element of readParts will be "introduction", "story" or "edification" (quotes for clarity).
Examples
0)
{"edification", "story", "introduction", "edification", "introduction", "story", "edification"}
Returns: 2
1)
{"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.

2)
{"story", "edification", "introduction", "story", "edification", "introduction", "introduction", "story", "edification", "introduction"}
Returns: 3
3)
{"introduction", "introduction", "introduction", "story", "story", "story", "edification", "edification", "edification"}
Returns: 0
4)
{"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.

Coding Area

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

Submitting as anonymous