Skip to main content
Back to problems
Codeforces
Medium
Arrays
Hash Maps
Sorting
Unique Values (Easy version)

Count how many distinct values appear in each test case, using the easy-version constraints.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.

Unique Values

gfg
Problem Statement

Problem

You are given an array of integers. Your task is to determine how many distinct values appear in the array.

For each test case, output the number of different elements present in the array.

This is the easy version of the problem, so the constraints are intended to allow straightforward counting-based solutions.

Input Format

  • The first line contains an integer tt — the number of test cases.
  • For each test case:
    • The first line contains an integer nn — the array length.
    • The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n.

Output Format

For each test case, print a single integer — the number of distinct values in the array.

Constraints

  • 1t1 \le t
  • 1n1 \le n
  • The array elements fit in standard 32-bit signed integers.
  • Exact limits are omitted here; use a solution that is linear or near-linear per test case.
Examples
Sample cases returned by the problem API.

Example 1

Input

3
5
1 2 2 3 1
4
7 7 7 7
6
4 5 4 6 5 7

Output

3
1
4

Explanation

  • Test case 1: distinct values are {1, 2, 3}.
  • Test case 2: only {7} appears.
  • Test case 3: distinct values are {4, 5, 6, 7}.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.