GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Tuesday 14 June 2022

[Solution] All Distinct Codeforces Solution | Codeforces Problem Solution 2022

B. All Distinct
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Sho has an array a consisting of n integers. An operation consists of choosing two distinct indices i and j and removing ai and aj from the array.

For example, for the array [2,3,4,2,5], Sho can choose to remove indices 1 and 3. After this operation, the array becomes [3,2,5]. Note that after any operation, the length of the array is reduced by two.

After he made some operations, Sho has an array that has only distinct elements. In addition, he made operations such that the resulting array is the longest possible.

More formally, the array after Sho has made his operations respects these criteria:

  • No pairs such that (i<j) and ai=aj exist.
  • The length of a is maximized.

Solution Click Below:-  CLICK HERE

Output the length of the final array.

Input

The first line contains a single integer t (1t103) — the number of test cases.

The first line of each test case contains a single integer n (1n50) — the length of the array.

The second line of each test case contains n integers ai (1ai104) — the elements of the array.

Output

For each test case, output a single integer — the length of the final array. Remember that in the final array, all elements are different, and its length is maximum.

No comments:

Post a Comment