Dance Team Pairing Challenge

Imagine you are helping Ninja, a dance coach, who needs to form dance pairs from the available boys and girls in a studio. Given the number of boys N, the number of girls M, and the possible pairings, determine the maximum number of dance pairs possible. Help him by determining the best arrangement of these pairs.

Input:

The input begins with an integer 'T' denoting the number of test cases.
For each test case, the first line contains three space-separated integers: N, M, and K representing the count of boys, girls, and potential pairings.
The following K lines contain space-separated integers 'a' and 'b', where 'a' is the index of a boy and 'b' is the index of a girl who can potentially be paired.

Output:

For each test case, output '1' if a set of the maximum possible pairs is returned. Otherwise, output '0'. Each result should be printed on its own line.

Example:

Input:
2
2 2 2
1 1
2 2
3 3 3
1 2
2 3
3 1
Output:
1
1

Constraints:

  • 1 ≤ T ≤ 5
  • 1 ≤ N ≤ 100
  • 1 ≤ M ≤ 100
  • 1 ≤ K ≤ 100
  • 1 ≤ a ≤ N
  • 1 ≤ b ≤ M

Note: There might be multiple sets of valid pairings; in such cases, you can return any valid configuration of pairs.

AnswerBot
4mo

The challenge involves forming dance pairs from available boys and girls based on potential pairings to maximize the number of pairs.

  • Parse the input to get the number of test cases, boys, girls, and p...read more

Help your peers!
Select
Add answer anonymously...

Tower Research Capital LLC Software Engineer interview questions & answers

A Software Engineer was asked Q. Given k and a DFS traversal string for a k-ary tree, construct the tree. The str...read more
A Software Engineer was asked Q. How would you determine if a graph contains a node with degree n?
A Software Engineer was asked Q. Can you describe the classes and functions involved in the design of a system li...read more

Popular interview questions of Software Engineer

A Software Engineer was asked Q1. Given k and a DFS traversal string for a k-ary tree, construct the tree. The str...read more
A Software Engineer was asked Q2. How would you determine if a graph contains a node with degree n?
A Software Engineer was asked Q3. Can you describe the classes and functions involved in the design of a system li...read more
Tower Research Capital LLC Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits