CardRemover
SRM 259 · 2005-08-22 · by Andrew_Lazarev
Problem Statement
There are some cards placed in a line. Each card is characterized by the three distinct letters written on it.
The conformity-level of two cards is the number of distinct letters that are common to both cards. For example, the conformity-level of "ABC" and "ACD" is 2 because the letters 'A' and 'C' are common to both cards, and the conformity-level of "ABC" and "DFE" is 0 because the two cards share no common letters.
You can remove a card if the conformity-level of its left neighbor and its right neighbor is greater than or equal to 2. Once a card is removed its left and right neighbors become neighbors themselves. The leftmost and rightmost cards are never removed.
Given a
Constraints
- cards will have between 2 and 50 elements, inclusive.
- Each element of cards will contain exactly 3 characters.
- Each element of cards will contain three distinct uppercase letters ('A'-'Z').
{"ABC",
"CDE",
"ABC",
"CDE",
"ABC"}
Returns: 3
You should not remove the third card before the second or the fourth.
{"ABC",
"CDE",
"EFG",
"GHI",
"IJK"}
Returns: 0
You can't remove anything.
{"ADR",
"FDB",
"ABC",
"CDE",
"ABD"}
Returns: 3
{"ABC","CAB"}
Returns: 0
{"ABC","DFT"}
Returns: 0
Submissions are judged against all 75 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class CardRemover with a public method int calculate(vector<string> cards) · 75 test cases · 2 s / 256 MB per case