hi, let Avik connect you.


** You can give your thought about this content and request modifications if needed from Ask For Modifications page. Thank You.

** You can check all the posts on the Posts page.

** More about me in the About Me section.

Distinct Enemies


  • Approach:

    1. Initiate a hashmap.

    2. Traverse through all the given elements.

    3. Once an element is encountered mark it as appeared.

    4. Return the size of the hashmap.


  • Time and Space Complexity:

      • Time Complexity: O(N)

      • Space Complexity: O(N)


Code [C++]

#include <bits/stdc++.h>

using namespace std;


int distinctEnemies(vector<int> &arr, int n)

{

unordered_map<int, bool>mymap;

for(int i=0; i<n; i++) mymap[arr[i]] = true;

return mymap.size();

}