C++ | Traverse and See if the Current Element is the Target or not
Intuition\n Describe your first thoughts on how to solve this problem. \nFought Soooo many bugs in this :()\n\n1. Calculate the totalSum.\n2. Also put all the e
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFought Soooo many bugs in this :()\n\n1. Calculate the totalSum.\n2. Also put all the elements in a map basically to find out if the outlier is present or not.\n3. Traverse and see if we can make the current element Target.\n\nLemme know if it\'s not optimal, this is what i could think of, off the top of my head. \n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int getLargestOutlier(vector<int>& nums) {\n      int totalSum = accumulate(nums.begin(), nums.end(), 0);\n      // Try to make every element the target and find if the residual is present or not..\n      unordered_map<int, int> umap;\n      for(int i=0; i<nums.size(); i++) umap[nums[i]]++;\n      int maxOutlier = INT_MIN;\n      for(int i=0; i<nums.size(); i++){\n        int target = nums[i];\n        int temp = totalSum - target;\n        if(umap.count(temp - target) && (temp - target != target || umap[temp - target] > 1)) maxOutlier = max(maxOutlier, temp - target);\n      }\n      return maxOutlier;\n    }\n};\n```
['C++']