Must-do problems: Sets
150 min · Intermediate
Need help? Ask a tutor on WhatsApp (opens in a new tab)Every problem here is about duplicates, common values, repeats or unique counts, and a set gives each one a short and fast solution. Read the input with Scanner, solve it with lists and sets only, and compare with the hints and solution when you are stuck.
What you will learn
- Drop duplicates and count different values with a HashSet
- Detect a repeat with the boolean returned by add
- Use TreeSet and LinkedHashSet when the output order matters
- Combine two collections with retainAll, removeAll and addAll
- Solve missing-number and consecutive-run problems with contains
Sign in to continue this lesson
Create an account to read every lesson, practise with the exercises and keep track of your progress.