
If N = 4 and the numbers on the top sides are: { 1, 2, 3, 2 } and the numbers on the bottom sides are: { 2, 4, 2, 2}
Then the minimum number of flips required is equal to 1.
We can flip the 2nd card, the top sides now become: { 1, 4, 3, 2 } and the bottom sides are: { 2, 2, 2, 2}. This results in getting the same numbers on the bottom side.
The first line contains a single integer ‘T’ denoting the number of test cases, then each test case follows:
The first line of each test case contains a single integer ‘N’ denoting the number of cards.
The second line of each test case contains the N integers ‘Top[i]’ denoting the number on the top side of the ith card.
The third line of each test case contains the N integers ‘Bottom[i]’ denoting the number on the bottom side of the ith card.
For each test case, print a single integer denoting the minimum number of flips required.
Output for each test case will be printed in a separate line.
You are not required to print anything; it has already been taken care of. Just implement the function.
1 <= T <= 10
1 <= N <= 200
1 <= Bottom[i], Top[i] <= 10
Time limit: 1 sec
We can simply find the number of flips required to make all the numbers on the top sides of the cards equal to ‘i’ where ‘i’ can range from ‘1’ to ‘10’. We can repeat the same thing for the bottom side, and finally, return the minimum number of flips out of them.
But note that for all cards to have the same value on either of the sides, the value should be either equal to the number on the top or on the bottom side of the first card.
The steps are as follows :