Equal Median
Practice
4.1 (20 votes)
Basic programming
Basics of implementation
Implementation
Medium
Problem
90% Success 11753 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

You will be given two arrays A and B of odd length N. In one swap operation, you can select a number from A and another number from B and swap them. You need to find the minimum number of swap operations required so that the median of those two arrays become equal. The median of the array is the element at the middle position in ascending order.

Constraints

  • 1 <= T <= 10
  • 1 <= N <= 10^5
  • 0 <= Ai, Bi <= 10^9

Note: N will always be an odd number.

Input Format

The first line contains T, the number of test cases. The first line of a test case contains an integer N. The second line contains N space separated integers representing the array A, and the third line contains N space separated integers representing the array B.

Output Format

For each test cases, print a single integer, the minimum number of swap operations necessary to make the median of those two arrays equal. If there’s no solution then print “-1”.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
17 votes
Tags:
ApprovedImplementationMediumOpenString Manipulation
Points:30
8 votes
Tags:
Basic ProgrammingBasics of ImplementationData StructuresHash MapsHash TablesImplementationMedium
Points:30
5 votes
Tags:
Basic ProgrammingBasics of ImplementationHiringImplementationMedium