#C6055. Unique Array Balance
Unique Array Balance
Unique Array Balance
Given two arrays of integers in each test case, your task is to determine whether the arrays have the same set of unique integers. Two arrays are considered BALANCED if, after removing duplicates, both arrays contain exactly the same elements; otherwise, they are UNBALANCED.
For each test case:
- The first number is an integer n representing the size of the first array.
- The second line contains n space-separated integers.
- The third number is an integer m representing the size of the second array.
- The fourth line contains m space-separated integers.
Your solution should read input from stdin
and output to stdout
.
Note: If \(S_1\) and \(S_2\) are the unique sets of the two arrays respectively, then the arrays are balanced if and only if \(S_1 = S_2\).
inputFormat
The input begins with a single integer T
(the number of test cases). Following that for each test case, there are 4 lines:
- An integer
n
denoting the number of elements in the first array. n
space-separated integers representing the first array.- An integer
m
denoting the number of elements in the second array. m
space-separated integers representing the second array.
All input is read from stdin
.
outputFormat
For each test case, output a single line containing either BALANCED
if the unique elements of both arrays match, or UNBALANCED
otherwise. All output should be written to stdout
.
2
5
1 2 3 4 5
5
5 4 3 2 1
4
2 3 3 3
3
3 2 1
BALANCED
UNBALANCED
</p>