Given an array **arr** containing integers of size **N**, the task is to delete all the elements from the array that have odd frequencies.

**Examples:**

Input:arr[] = {3, 3, 3, 2, 2, 4, 7, 7}

Output:{2, 2, 7, 7}

Explanation:

Frequency of 3 = 3

Frequency of 2 = 2

Frequency of 4 = 1

Frequency of 7 = 2

Therefore, the elements 3 and 4 have odd frequencies, and hence the are removed.

Input:arr[] = {1, 3, 3, 1, 2, 5, 6, 5}

Output:{1, 3, 3, 1, 5, 5}

**Approach:**

- Create a map and store the frequency of each element from the array to the same map.
- Then, traverse the array and find out which elements have odd frequencies with the help of the map.
- Ignore all those elements which have odd frequencies and print rest of them

Below is the implementation of the above approach:

## C++

`// C++ program to removes all odd ` `// frequency elements from an Array ` ` ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function that removes the ` `// elements which have odd ` `// frequencies in the array ` `void` `remove` `(` `int` `arr[], ` `int` `n) ` `{ ` ` ` `// Create a map to store the ` ` ` `// frequency of each element ` ` ` `unordered_map<` `int` `, ` `int` `> m; ` ` ` `for` `(` `int` `i = 0; i < n; i++) { ` ` ` `m[arr[i]]++; ` ` ` `} ` ` ` ` ` `// Remove the elements which ` ` ` `// have odd frequencies ` ` ` `for` `(` `int` `i = 0; i < n; i++) { ` ` ` ` ` `// If the element has ` ` ` `// odd frequency then skip ` ` ` `if` `((m[arr[i]] & 1)) ` ` ` `continue` `; ` ` ` ` ` `cout << arr[i] << ` `", "` `; ` ` ` `} ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `arr[] ` ` ` `= { 3, 3, 3, 2, ` ` ` `2, 4, 7, 7 }; ` ` ` `int` `n = ` `sizeof` `(arr) / ` `sizeof` `(arr[0]); ` ` ` ` ` `// Function call ` ` ` `remove` `(arr, n); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to removes all odd ` `// frequency elements from an Array ` `import` `java.util.*; ` ` ` `class` `GFG { ` ` ` ` ` `// Function that removes the ` ` ` `// elements which have odd ` ` ` `// frequencies in the array ` ` ` `static` `void` `remove(` `int` `arr[], ` `int` `n) { ` ` ` `// Create a map to store the ` ` ` `// frequency of each element ` ` ` `HashMap<Integer, Integer> mp = ` `new` `HashMap<Integer, Integer>(); ` ` ` `for` `(` `int` `i = ` `0` `; i < n; i++) { ` ` ` `if` `(mp.containsKey(arr[i])) { ` ` ` `mp.put(arr[i], mp.get(arr[i]) + ` `1` `); ` ` ` `} ` `else` `{ ` ` ` `mp.put(arr[i], ` `1` `); ` ` ` `} ` ` ` `} ` ` ` ` ` `// Remove the elements which ` ` ` `// have odd frequencies ` ` ` `for` `(` `int` `i = ` `0` `; i < n; i++) { ` ` ` ` ` `// If the element has ` ` ` `// odd frequency then skip ` ` ` `if` `((mp.containsKey(arr[i]) && mp.get(arr[i]) % ` `2` `== ` `1` `)) ` ` ` `continue` `; ` ` ` ` ` `System.out.print(arr[i] + ` `", "` `); ` ` ` `} ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main(String[] args) { ` ` ` `int` `arr[] = { ` `3` `, ` `3` `, ` `3` `, ` `2` `, ` `2` `, ` `4` `, ` `7` `, ` `7` `}; ` ` ` `int` `n = arr.length; ` ` ` ` ` `// Function call ` ` ` `remove(arr, n); ` ` ` ` ` `} ` `} ` ` ` `// This code is contributed by Rajput-Ji ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to removes all odd ` `# frequency elements from an Array ` ` ` `# Function that removes the ` `# elements which have odd ` `# frequencies in the array ` `def` `remove(arr, n) : ` ` ` ` ` `# Create a map to store the ` ` ` `# frequency of each element ` ` ` `m ` `=` `dict` `.fromkeys(arr,` `0` `); ` ` ` `for` `i ` `in` `range` `(n) : ` ` ` `m[arr[i]] ` `+` `=` `1` `; ` ` ` ` ` `# Remove the elements which ` ` ` `# have odd frequencies ` ` ` `for` `i ` `in` `range` `(n) : ` ` ` ` ` `# If the element has ` ` ` `# odd frequency then skip ` ` ` `if` `((m[arr[i]] & ` `1` `)) : ` ` ` `continue` `; ` ` ` ` ` `print` `(arr[i],end` `=` `", "` `); ` ` ` `# Driver code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` ` ` `arr ` `=` `[ ` `3` `, ` `3` `, ` `3` `, ` `2` `, ` ` ` `2` `, ` `4` `, ` `7` `, ` `7` `]; ` ` ` `n ` `=` `len` `(arr); ` ` ` ` ` `# Function call ` ` ` `remove(arr, n); ` ` ` `# This code is contributed by Yash_R ` |

*chevron_right*

*filter_none*

## C#

`// C# program to removes all odd ` `// frequency elements from an Array ` `using` `System; ` `using` `System.Collections.Generic; ` ` ` `class` `GFG { ` ` ` ` ` `// Function that removes the ` ` ` `// elements which have odd ` ` ` `// frequencies in the array ` ` ` `static` `void` `remove(` `int` `[]arr, ` `int` `n) { ` ` ` ` ` `// Create a map to store the ` ` ` `// frequency of each element ` ` ` `Dictionary<` `int` `, ` `int` `> mp = ` `new` `Dictionary<` `int` `, ` `int` `>(); ` ` ` `for` `(` `int` `i = 0; i < n; i++) { ` ` ` `if` `(mp.ContainsKey(arr[i])) { ` ` ` `mp[arr[i]] = mp[arr[i]] + 1; ` ` ` `} ` `else` `{ ` ` ` `mp.Add(arr[i], 1); ` ` ` `} ` ` ` `} ` ` ` ` ` `// Remove the elements which ` ` ` `// have odd frequencies ` ` ` `for` `(` `int` `i = 0; i < n; i++) { ` ` ` ` ` `// If the element has ` ` ` `// odd frequency then skip ` ` ` `if` `((mp.ContainsKey(arr[i]) && mp[arr[i]] % 2 == 1)) ` ` ` `continue` `; ` ` ` ` ` `Console.Write(arr[i] + ` `", "` `); ` ` ` `} ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `Main(String[] args) { ` ` ` `int` `[]arr = { 3, 3, 3, 2, 2, 4, 7, 7 }; ` ` ` `int` `n = arr.Length; ` ` ` ` ` `// Function call ` ` ` `remove(arr, n); ` ` ` `} ` `} ` ` ` `// This code is contributed by 29AjayKumar ` |

*chevron_right*

*filter_none*

**Output:**

2, 2, 7, 7,

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.