020-002-006
Collections: Removing Duplicates with HashSet
Medium
Problem Description
Collections: Removing Duplicates with HashSet
In this problem, you will create a program that reads n integers, adds them to a HashSet to automatically remove duplicates, and displays the set size and whether a specific value (10) is contained to standard output.
Learning Objective: Understand HashSet characteristics (no duplicates, no order)
Overview
HashSet is a collection that doesn't allow duplicate elements. Even if you try to add the same element, only one will be retained. Also, element order is not guaranteed.
Specifications
Create a program to manage a set of integers.
- First input: Number of elements n to attempt adding to set
- Next n inputs: Integer values to attempt adding (may contain duplicates)
- Output set size
- Check if set contains specific value (contains 10)
- Output result as "Contains 10: true" or "Contains 10: false"
Input Format
<count>
<integer1>
<integer2>
...
Output Format
Size: <size after removing duplicates>
Contains 10: <true/false>
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up