Must-do problems: Maps
180 min · Intermediate
Need help? Ask a tutor on WhatsApp (opens in a new tab)Every problem here is solved with a map: a frequency map, a grouping map, a lookup map, or a map that remembers what was seen so far. Read the input with Scanner, decide first what the key and the value are, pick the map that gives the output order the problem asks for, and run every test before opening a hint.
What you will learn
- Count, total and group data with a map in one pass
- Use a map to remember what was seen so far (first repeat, two-sum, prefix sums)
- Choose HashMap, LinkedHashMap or TreeMap for the output order a problem needs
- Build keys for grouping, such as sorted letters for anagrams
- Solve an LRU cache with an access-order LinkedHashMap
Sign in to continue this lesson
Create an account to read every lesson, practise with the exercises and keep track of your progress.