Unique Element Report

Easy
0/40
0 upvote

Problem statement

You are given a list of N integers which may contain duplicate values. Your task is to analyze this list and produce a report containing two key pieces of information:


1) The total count of unique (distinct) elements in the list.


2) A sorted list of these unique elements in non-decreasing order.


Detailed explanation ( Input/output format, Notes, Images )
Input Format:
The first line of input contains an integer 'N', the number of elements in the list.

The second line contains 'N' space-separated integers, representing the list of numbers.


Output Format:
The first line of output must be a single integer representing the count of unique elements.

The second line of output must contain the unique elements, sorted in non-decreasing order and separated by single spaces.


Note:
The most efficient way to solve this is to use a data structure that automatically handles uniqueness, such as a Set or a Hash Set.
Sample Input 1:
6
1 22 11 22 5 6


Sample Output 1:
5
1 5 6 11 22


Explanation for Sample 1:
The unique elements in the list `{1, 22, 11, 22, 5, 6}` are `{1, 5, 6, 11, 22}`.
The count of these unique elements is 5.
When sorted, the list of unique elements is `{1, 5, 6, 11, 22}`.


Sample Input 2:
5
5 4 3 2 1


Sample Output 2:
5
1 2 3 4 5


Explanation for Sample 2:
All elements are already unique. The count is 5.
The sorted list of unique elements is `{1, 2, 3, 4, 5}`.


Expected Time Complexity:
The expected time complexity is O(N logN).


Constraints:
1 <= N <= 10^5
-10^9 <= list element <= 10^9

Time limit: 1 sec
Approaches (1)
Unique Element Report
Time Complexity
Space Complexity
Code Solution
(100% EXP penalty)
Unique Element Report
Full screen
Console