HashMap and HashSet Questions
1. Create a HashMap and add key-value pairs to it.
Input: {"Alice": 85, "Bob": 78, "Charlie": 92}
2. Retrieve the value for a given key from the HashMap.
Input: Key: "Bob"
3. Check if a specific key exists in the HashMap.
Input: Key: "Alice"
4. Check if a specific value exists in the HashMap.
Input: Value: 92
5. Iterate over a HashMap using a for-each loop.
Input: {"Math": 90, "Science": 85, "English": 88}
6. Remove a key-value pair from the HashMap.
Input: Key: "Charlie"
7. Find the size of the HashMap.
Input: {"Red": 1, "Blue": 2}
8. Replace the value of an existing key in the HashMap.
Input: Key: "Bob", New Value: 95
9. Clear all key-value pairs from the HashMap.
Input: {"a": 1, "b": 2, "c": 3}
10. Count the frequency of characters in a string using HashMap.
Input: "programming"
11. Count the frequency of words in a sentence using HashMap.
Input: "this is a test this is only a test"
12. Given an array, find the element that appears more than once using HashMap.
Input: [1, 2, 3, 2, 4]
13. Merge two HashMaps.
Input: {"a": 1, "b": 2} and {"b": 3, "c": 4}
14. Find the key with the maximum value in a HashMap.
Input: {"a": 10, "b": 50, "c": 30}
HashMap and HashSet Questions
15. Sort the HashMap by keys.
Input: {"banana": 1, "apple": 3, "cherry": 2}
HashSet Questions
1. Create a HashSet and add elements to it.
Input: [10, 20, 30, 40]
2. Check if a specific element exists in the HashSet.
Input: Element: 20
3. Remove an element from the HashSet.
Input: Element: 30
4. Iterate over a HashSet.
Input: [1, 2, 3, 4, 5]
5. Find the size of a HashSet.
Input: [7, 8, 9]
6. Remove all elements from the HashSet.
Input: [11, 12, 13]
7. Add duplicate elements and observe the behavior of HashSet.
Input: [5, 5, 10, 10]
8. Convert a HashSet to an array.
Input: [100, 200, 300]
9. Convert a list to a HashSet to remove duplicates.
Input: [1, 2, 2, 3, 4, 4]
10. Find the union of two HashSets.
Input: [1, 2, 3] and [3, 4, 5]
11. Find the intersection of two HashSets.
Input: [1, 2, 3] and [2, 3, 4]
12. Find the difference between two HashSets.
Input: [1, 2, 3] and [3, 4, 5]
HashMap and HashSet Questions
13. Check if a HashSet is a subset of another HashSet.
Input: [1, 2] is subset of [1, 2, 3, 4]
14. Given an array, find all unique elements using a HashSet.
Input: [4, 5, 5, 6, 7, 7]
15. Check if all characters in a string are unique using HashSet.
Input: "hello"