easy cpp solution
IntuitionThe goal is to find an outlier in the given array. The outlier should satisfy the equation:outlier=total sum of all elements−2×(some element in the arr
# Intuition
The goal is to find an outlier in the given array. The outlier should satisfy the equation:

outlier=total sum of all elements−2×(some element in the array)
This equation arises because:
There is one number in the array that equals the sum of some subset of elements.By rearranging, we find that the outlier should be the difference between the total sum and twice another element in the array.

To efficiently find this outlier, we:

Compute the total sum of the array.

Iterate over the array to check if sum - 2 * nums[i] exists.

Ensure that the found number is at a different index (so we do not use the same number twice).

Return the largest outlier found.



# Approach
1)Sort the array to ensure that we process numbers in increasing order, which simplifies the search for the largest outlier.

2)Compute the total sum of the array.

3)Use a map (mpp) to store each element’s index, allowing quick lookups.

4)Iterate from the largest number to the smallest (to maximize the outlier):

5)For each number nums[i], check if sum - 2 * nums[i] exists in the map.

6)Ensure that the found element is not at the same index as i (to avoid counting the same number twice).

7)Keep track of the largest valid outlier found so far.

8)Return the largest valid outlier.




# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
Sorting the array: o(NlogN)
computing the total sum =o(n)
building the map = o(n)
finding the outlier = o(n)
overall=O(NlogN)

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
o(n) for storing n elements in the map

# Code
```cpp []
class Solution {
public:
    int getLargestOutlier(vector<int>& nums) {
      sort(nums.begin(),nums.end());
      int n = nums.size();
      int sum = 0;
      map<int,int> mpp;
      
      for(int i = 0 ; i< n ; i++){
        sum+=nums[i];
        mpp[nums[i]]=i;
      }  
      int outlier=INT_MIN ;
      int i = n-1;
      
      while(i>=0){
        if(mpp.count(sum-2*nums[i]) && mpp[sum-2*nums[i]]!=i){
            outlier=max(outlier,sum-2*nums[i]);
           
        }
        i--;
      }
      return outlier;
    }
};



```
['C++']