Two-Pointers Detailed Explanation
we can use Two Pointers also for this problem.Approach:When outlier is right of 1st remaining element(nums[l], sum of special numbers)
If sum of all special ele
# we can use *Two Pointers* also for this problem.

## Approach:
<!-- Describe your approach to solving the problem. -->
#### When outlier is right of 1st remaining element(nums[l], sum of special numbers)
- If ***sum of all special elements*** { Total sum - 1stElement(nums[l]) - outlier(nums[r]) } ***= 1stElement(nums[l])***,
Then return the outlier(nums[r]) as array is sorted this is the max outlier possible.
- If ***sum of all special elements*** { Total sum - 1stElement(nums[l]) - outlier(nums[r]) } ***> 1stElement(nums[l])***,
Then to make the **sum of all special elements** lower, increase the 1stElement(nums[l]) by incrementing l to l+1 (doing r-- further decreases the outlier(nums[r]) and hence increases **sum of all special elements**, so only way is moving right by l++).
- If ***sum of all special elements*** { Total sum - 1stElement(nums[l]) - outlier(nums[r]) } ***< 1stElement(nums[l])***,
Then to make the **sum of all special elements** higher, decrease the outlier(nums[r]) by decrementing r to r-1 (doing l++ further increases the 1stElement(nums[l]) and hence decreases **sum of all special elements**, so only way is moving left by r--).



#### When outlier is left of 1st remaining element(nums[l], sum of special numbers)
- If ***sum of all special elements*** { Total sum - 1stElement(nums[r]) - outlier(nums[l]) } ***= 1stElement(nums[r])***,
Then update the outlier(nums[l]) to ans as we move right we might get higher outlier.
- If ***sum of all special elements*** { Total sum - 1stElement(nums[r]) - outlier(nums[l]) } ***> 1stElement(nums[r])***,
Then to make the **sum of all special elements** lower, increase the outlier(nums[l]) by incrementing l to l+1 (doing r-- further decreases the 1stElement(nums[r]) and hence increases **sum of all special elements**, so only way is moving right by l++).
- If ***sum of all special elements*** { Total sum - 1stElement(nums[r]) - outlier(nums[l]) } ***< 1stElement(nums[r])***,
Then to make the **sum of all special elements** higher, decrease the 1stElement(nums[r]) by decrementing r to r-1 (doing l++ further increases the outlier(nums[l]) and hence decreases **sum of all special elements**, so only way is moving left by r--).


# Code
```java []
class Solution {
    public int getLargestOutlier(int[] nums) {

        // *** Two-Pointer TC: (NlogN), SC: (K), K for sorting algo

        Arrays.sort(nums);
        int sum = 0;
        for (int e : nums)
            sum += e;

        int l = 0;
        int r = nums.length - 1;

        // when outlier is right of 1st remaining element(sum of special numbers)
        while (l < r) {
            if (sum - nums[l] - nums[r] == nums[l]) {
                return nums[r];// highest outliear as array is sorted non-decreasing
            } else if (sum - nums[l] - nums[r] > nums[l])
                l++;
            else
                r--;
        }
        l = 0;
        r = nums.length - 1;
        int ans = -1;

        // when outlier is left of 1st remaining element(sum of special numbers)
        while (l < r) {
            if (sum - nums[r] - nums[l] == nums[r]) {
                ans = nums[l];// every time update for higher outlier as we move to right
                l++;
            } else if (sum - nums[r] - nums[l] > nums[r])
                l++;
            else
                r--;
        }
        return ans;
    }
}
```


# Complexity
- Time complexity: O(NlogN)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
        NlogN for sorting algorithm
        At max 2N for two loops

- Space complexity: O(K)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
        K space used by sorting algorithm


Let me know if there's anything else I can do to improve this approach.
['Array', 'Two Pointers', 'Sorting', 'Java']