Kevin and His Cards Problem Statement

Kevin has two packs of cards. The first pack contains N cards, and the second contains M cards. Each card has an integer written on it. Determine two results: the total number of distinct card types when considering both packs together, and the number of card types present in both packs.

Note:

Two cards are of different types if their numbers differ.

Example:

Input:
T = 1
N = 3, M = 3
First pack: [2, 3, 5]
Second pack: [3, 4, 5]
Output:
4 2
Explanation:

The distinct card types when both packs are combined are {2, 3, 4, 5}, totaling 4. The common card types between the two packs are {3, 5}, totaling 2.

Constraints:

  • 1 <= T <= 10
  • 1 <= N, M <= 500
  • -10^9 <= arr[i] <= 10^9
  • Time Limit: 1 sec
AnswerBot
6d

Find total distinct card types and common card types between two packs of cards.

  • Create a set to store distinct card types when combining both packs.

  • Iterate through each pack and add card types to the ...read more

Help your peers!
Add answer anonymously...
ZS Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter