Connection Status:
Competition Arena > CardRemover
SRM 259 · 2005-08-22 · by Andrew_Lazarev · Dynamic Programming
Class Name: CardRemover
Return Type: int
Method Name: calculate
Arg Types: (vector<string>)
Problem Statement

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 String[] cards, determine the maximum quantity of cards that you can remove.

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').
Examples
0)
{"ABC",
 "CDE",
 "ABC",
 "CDE",
 "ABC"}
Returns: 3

You should not remove the third card before the second or the fourth.

1)
{"ABC",
 "CDE",
 "EFG",
 "GHI",
 "IJK"}
Returns: 0

You can't remove anything.

2)
{"ADR",
 "FDB",
 "ABC",
 "CDE",
 "ABD"}
Returns: 3
3)
{"ABC","CAB"}
Returns: 0
4)
{"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.

Coding Area

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

Submitting as anonymous