Simple C++ solution. Beats >99%.
IntuitionWe know that exactly one number is outlier and the other is a sum of all numbers. Therefore we simply sum all the numbers first and then do a linear sc
# Intuition
We know that exactly one number is outlier and the other is a sum of all numbers. Therefore we simply sum all the numbers first and then do a linear scan to check if the given number can be an _outlier_. The remaining sum will be the double of the "other" non-special number. Therefore we halve the sum and check if the "other" number was present in the original array. There can be multiple solutions, therefore we only take the next possible answer if it's greater than the last found answer.

# Approach
* Create a frequency map `allNums` of all the numbers.
* In the same loop we can also sum all the numbers and store it in `sum`.
* Then we do a linear scan testing if the given number can be an outlier.
  * For this, we deduct the current candidate for the `outlier` from the `sum`   
  * We check if the sum is divisble by 2. If so, we get the other non-special number by halving the deducted `sum`.
  * Then we check if this `other` number is present in the dictionary.
  * One edge case we need to lookout for is if `other` equals `outlier`, the frequency of this number must be at least 2 to make it a valid solution.
  * If the above condition satisfies, we store the `outlier` if it's greater than the previously found answer.

# Complexity
- **Time complexity**: $$O(n)$$ for summing and counting the frequency, and then again $$O(n)$$ for the linear scan. So the total is $$O(n)$$.

- **Space complexity**: $$O(n)$$ for storing the frequency of all the numbers.


# Code
```cpp []
class Solution {
public:
    int getLargestOutlier(vector<int>& nums) {
        unordered_map<int, int> allNums;
        int sum = 0;

        for (int n : nums) {
            allNums[n]++;
            sum += n;
        }

        int ans = INT_MIN;

        for (int outlier : nums) {
            int sumWithoutOutlier = sum - outlier;
            if (sumWithoutOutlier % 2 == 0) {
                int other = sumWithoutOutlier / 2;
                auto it = allNums.find(other);
                if (it != allNums.end()) {
                    if (other == outlier) {
                        if (it->second >= 2) {
                            ans = max(ans, outlier);
                        }
                    } else {
                        ans = max(ans, outlier);
                    }
                }
            }
        }

        return ans;
    }
};
```
['C++']