Hashing and maps in Java
Why it matters
Hash maps are used for counts, grouping, and fast lookup.
Problems to practice
- Valid Anagram
- Top K Frequent Elements
- Subarray Sum Equals K
- First Non-Repeating Character
- Longest Consecutive Sequence
Example: frequency count
Map<Character, Integer> freq = new HashMap<>();
for (char ch : s.toCharArray()) {
freq.put(ch, freq.getOrDefault(ch, 0) + 1);
}Interview guidance
Use HashMap when average O(1) lookup is enough. Use TreeMap when order matters.
Can you explain it without the notes?
Hashing and maps in Java
Use your own words. Explain an example and one limitation before checking the explanation.
Check your explanation
Why it matters
Turn this concept into a clear answer.
Practice this conceptAdapted from 15_DSA_JAVA.md · “3. Hashing and maps in Java”. Examples are study fragments; framework behavior can depend on your version.