Given a list of Card objects, find all the cards in the list that are duplicates.
Duplicates are defined as two cards with the same rank and color.
Cards are similar to, but not exactly like, common playing cards.
final class Card {
int rank; // any integer
Color color; // RED, GREEN, BLUE, YELLOW, etc.
int cardId; // uniquely identifies a card object
}
List<Card> findDuplicates(List<Card> cards);Input: [ [5, YELLOW, aa] , [2, BLUE, bb] ,[3, YELLOW, cc] , [5, YELLOW, dd] , [3, GREEN, ee] , [2, BLUE, ff] , [5, YELLOW, gg]]
Output: [ [5, YELLOW, aa] , [2, BLUE, bb] ,[3, YELLOW, cc] , [3, GREEN, ee]]Interviewer requested that he needed the most optimized solution O(n) and i could use all the space i needed.