Archive / 2019 / Final Round — Day 2
Paths with Cards
You and your friend Praveen came up with a new game with playing cards. Praveen would pick 2 cards from the pack and you have to create a path between the two cards using the rest of the cards in the pack of cards. But the problem is that each card has a cost. So, the target is to keep the cost as low as possible.
A pack of playing cards has 52 cards. Each card belongs to one of the following suits.
- Diamonds (♦) - D
- Clubs (♣) - C
- Hearts (♥) - H
- Spades (♠) - S
There will be 13 cards in each suit.
- Ace - A
- 2 - 2
- 3 - 3
- 4 - 4
- 5 - 5
- 6 - 6
- 7 - 7
- 8 - 8
- 9 - 9
- 10 - 10
- Jack - J
- Queen - Q
- King - K

Each card can be identified by the letter of the suit followed by the value of the card.
Ex:
- King of Clubs - “CK”
- Ace of Diamond - “DA”
- 3 of Hearts - “H3”
- 10 of Spades - “S10”
In a path, any consecutive pair of cards there can be only 1 change from the following 2 changes.
-
Increase or decrease the value by 1. Ace(A) can be used to go from a King to 2 or vice versa.
Example:- K-> A -> 2 -> 3
- K -> Q -> J -> 10
-
Change the suit to 1 higher it or lower it and go circle (order given above).
Example:- Clubs -> Hearts -> Spades -> Diamonds
- Clubs -> Diamonds -> Spades -> Hearts
For example, these are possible ways to go from 10 of Diamonds (D10) to 9 of Hearts (H9).
- D10 -> C10 -> H10 -> H9
- D10 -> D9 -> S9 -> H9
- D10 - DJ -> CJ -> CQ -> HQ -> HJ -> SJ -> S10 -> S9 -> H9
Your task is to write a program to find a path from the 2 given cards, which has the minimum cost.
If there are multiple paths with the minimum cost, the one with the minimum number of cards should be selected.
It is guaranteed that there are no multiple paths that have the minimum cost and the same no. of cards.
Input Format
asd
Output Format
asd
Constraints
- 0 \(\leq\) cost of a card \(\leq\) 105
- 2 \(\leq\) L \(\leq\) 52
- 1 \(\leq\) C \(\leq\) 107
Limits
- Time Limit: 1s
- Memory Limit: 256MB
Sample Input 0
D10 H9
61 74 78 61 34 83 85 66 21 1 2 1 35
56 46 99 22 95 82 58 84 25 53 43 2 38
33 57 87 80 75 37 88 77 2 2 2 3 72
100 39 22 100 67 41 42 41 2 49 2 1 84
Sample Output 0
6 11
D10 DJ SJ HJ H10 H9
Open on HackerRank ↗ · Markdown source · Back to the archive