DeckOfCards
SRM 732 · 2018-03-29 · by ltdtl
Problem Statement
You found a deck of slightly non-traditional playing cards. Each card has a value and a suit. The value of each card is a positive integer, and the suit is a lowercase English letter ('a'-'z'). We will use (v, s) to denote a card with value v and suit s.
You want to know whether the deck is perfect. A perfect deck has two properties:
- All cards in the deck are distinct. (I.e., no two cards share both value and suit.)
- For any two cards (v1, s1) and (v2, s2) in the deck, the deck also contains the cards (v1, s2) and (v2, s1).
You are given the following data:
- an
int n: the number of cards in the deck - a
int[] value with n elements: the values of the cards in the deck - a
String suit with n elements: the suits of the cards in the deck
Constraints
- n will be between 1 and 50, inclusive.
- value will contain exactly n elements.
- Each element of value will be between 1 and 1,000,000,000, inclusive.
- suit will be of length n exactly.
- Suit will only contain lower-case alphabets ('a'-'z').
1
{10}
"z"
Returns: "Perfect"
There is only one card in the deck: (10, 'z'). The deck is obviously perfect.
3
{1,2,3}
"hhh"
Returns: "Perfect"
4
{2,3,2,3}
"hcch"
Returns: "Perfect"
3
{1,1,1}
"hch"
Returns: "Not perfect"
This deck is not perfect because it contains two copies of the card (1, 'h').
4
{1,2,3,4}
"hhcc"
Returns: "Not perfect"
This deck is not perfect. For example, the presence of cards (1, 'h') and (3, 'c') implies that the cards (3, 'h') and (1, 'c') should also be in the deck, but both of them are missing.
Submissions are judged against all 71 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class DeckOfCards with a public method string IsValid(int n, vector<int> value, string suit) · 71 test cases · 2 s / 256 MB per case