Hashing || O(N) time complexity || Easy CPP code
/ The basic idea was to create a frequency count of each element , so from this step it helped me to eliminate two things first the elements which were repeatin
/* The basic idea was to create a frequency count of each element , so from this step it helped me to eliminate two things first the elements which were repeating , and second the elements x+1 and x-1 . Then they are stored in a different array , now I have the actual array which is following the above conditon of lonely array. Now its very simple we just have to check whether any adjacent elements are still not holding those condition if not they are the elements to be shown.\n*/\nclass Solution {\npublic:\n    vector<int> findLonely(vector<int>& nums) {\n        unordered_map<int , int > mp;\n        \n        for ( auto i : nums) mp[i]++;\n        \n        vector <int> a , b;\n        \n       for ( int i = 0 ; i < nums.size() ; i++){\n           if (mp[nums[i]] == 1 and mp[nums[i]-1]==0 and mp[nums[i]+1] == 0)\n               a.push_back(nums[i]);\n       }\n        \n       for ( int i = 0 ; i < a.size() ; i++){\n           if ( i == 0 ){\n               if ( a.size() > 1 and a[i+1] != a[i]-1 )\n                   b.push_back(a[i]);\n               else return a;\n           }\n           \n           else if ( i == a.size() - 1){\n               if ( a.size()>1 and a[i-1]+1 != a[i] )\n                   b.push_back(a[i]);\n               else return a;\n           }\n           \n          else if ( a[i-1] +1 != a[i] and a[i] != a[i+1]-1)\n               b.push_back(a[i]);\n       }\n        \n      \n        \n    \n    return b;\n    }\n    \n    \n};
[]