Simple Solution ✅ beats 💯
Intuition\n Describe your first thoughts on how to solve this problem. \nThe function appears to find the largest number (outlier) from the input list nums such
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe function appears to find the largest number (outlier) from the input list nums such that, when removed, the remaining numbers can form a valid condition related to their sum. Specifically:\n\nThe remaining sum must be even.\nHalf of this sum must also exist in the list of remaining numbers.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. initail Setup\n\n```\nhashset = set(nums)\ntotal = sum(nums)\nfreq = Counter(nums)\nres12456 = -1001\n\n```\n\nhashset: A set of all unique numbers in nums (used for efficient lookups, though unused in the rest of the code).\ntotal: Sum of all numbers in nums.\nfreq: A Counter object to track the frequency of each number in nums.\nres12456: Stores the largest outlier satisfying the condition. It is initialized to -1001 (assuming no number in nums is smaller than -1000).\n\n2. This loop processes each number in nums to check if it can be an outlier.\n\n```\nfor num in nums:\n```\n\n3. Temporarily Removing a Number:\n\n```\ntotal -= num\nfreq[num] -= 1\nif freq[num] == 0:\n    freq.pop(num)\n\n```\n\ntotal -= num: Subtract the current number num from the total.\nfreq[num] -= 1: Reduce the frequency of num in the freq counter.\nif freq[num] == 0: Remove num from freq if its frequency becomes zero.\n\n4. Checking Conditions:\n\n```\nif total % 2 == 0 and (total // 2) in freq:\n    res12456 = max(res12456, num)\n\n```\n\ntotal % 2 == 0: Ensures the sum of the remaining numbers is even.\n(total // 2) in freq: Checks if half of the remaining total exists as one of the remaining numbers.\nres12456 = max(res12456, num): Updates res12456 to the maximum of its current value and num if conditions are met.\n\n5. Restoring the State:\n\n```\ntotal += num\nfreq[num] += 1\n\n```\n\nAfter processing num, the total and freq are restored to their original state to process the next number.\n\n# Complexity\n- Time complexity: O( N )\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n\n- Space complexity: O( N )\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nclass Solution:\n    def getLargestOutlier(self, nums: List[int]) -> int:\n        hashset = set(nums)\n        total = sum(nums)\n        freq = Counter(nums)\n        res12456 = -1001\n        \n        for num in nums:\n            total -= num\n            freq[num] -= 1\n\n            if freq[num] == 0:\n                freq.pop(num)\n\n            if total % 2 == 0 and (total // 2) in freq:\n                res12456 = max(res12456, num)\n\n            total += num\n            freq[num] += 1\n\n        return res12456\n        \n                        \n                    \n                \n```
['Python3']