[go: up one dir, main page]

0% found this document useful (0 votes)
4 views2 pages

ArList.hashmap.hashset.problems

The document outlines various programming problems related to ArrayLists, HashMaps, and HashSets. It includes tasks such as removing even numbers, finding duplicates, counting frequencies, and checking for anagrams. Each problem is accompanied by example inputs and expected outputs.

Uploaded by

rojamanirai1106
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

ArList.hashmap.hashset.problems

The document outlines various programming problems related to ArrayLists, HashMaps, and HashSets. It includes tasks such as removing even numbers, finding duplicates, counting frequencies, and checking for anagrams. Each problem is accompanied by example inputs and expected outputs.

Uploaded by

rojamanirai1106
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

### **ArrayList Problems**

#### **Basic**
1. **Remove Even Numbers**
Write a method to remove all even numbers from an ArrayList of integers.
*Input:* `[1, 2, 3, 4, 5, 6]`
*Output:* `[1, 3, 5]`

2. **Find Duplicates**
Write a method to find duplicate elements in an ArrayList.
*Input:* `[1, 2, 3, 2, 4, 5, 1]`
*Output:* `[1, 2]`

#### **Medium**
3. **Intersection of Two ArrayLists**
Write a method to return the common elements between two ArrayLists.
*Input:* `[1, 2, 3, 4]` and `[3, 4, 5, 6]`
*Output:* `[3, 4]`

4. **Custom Sorting of ArrayList**


Sort an ArrayList of Strings by their lengths.
*Input:* `["apple", "banana", "kiwi", "pear"]`
*Output:* `["kiwi", "pear", "apple", "banana"]`

---

### **HashMap Problems**

#### **Basic**
1. **Count Frequencies**
Given a list of integers, count the frequency of each number using a HashMap.
*Input:* `[1, 2, 2, 3, 3, 3]`
*Output:* `{1=1, 2=2, 3=3}`

2. **Character Count in a String**


Count how many times each character appears in a given string.
*Input:* `"programming"`
*Output:* `{p=1, r=2, o=1, g=2, a=1, m=2, i=1, n=1}`

#### **Medium**
3. **First Non-Repeating Character**
Find the first non-repeating character in a string using HashMap.
*Input:* `"aabbcddeff"`
*Output:* `'c'`

4. **Are Two Strings Anagrams?**


Check if two strings are anagrams using HashMap.
*Input:* `"listen"` and `"silent"`
*Output:* `true`

---

### **HashSet Problems**

#### **Basic**
1. **Remove Duplicates from ArrayList**
Convert an ArrayList with duplicates into a list with unique elements using
HashSet.
*Input:* `[1, 2, 2, 3, 4, 4, 5]`
*Output:* `[1, 2, 3, 4, 5]`

2. **Check for Duplicates**


Given an array, check if it contains any duplicates.
*Input:* `[1, 2, 3, 4, 5, 2]`
*Output:* `true`

#### **Medium**
3. **Union and Intersection**
Find the union and intersection of two integer arrays using HashSet.
*Input:* `[1, 2, 3]`, `[2, 3, 4]`
*Output:*
- Union: `[1, 2, 3, 4]`
- Intersection: `[2, 3]`

4. **Find Missing Number**


Given an array with numbers from 1 to N, find the missing number using HashSet.

*Input:* `[1, 2, 4, 5]`


*Output:* `3`

You might also like