C++ Simple Solution Using set and Priority_queue
Intuition\n Describe your first thoughts on how to solve this problem. \nIntuition for that problem is that find all unique element present in the array ,Now we
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIntuition for that problem is that find all unique element present in the array ,Now we want  greatest element of which its negation exist then put all the positive element in the priority-queue and simply iterating the pq and checking .\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. We use a priority queue (pq) to keep track of positive integers in descending order.\nWe use a set (st) to keep track of all unique integers in the array.\n1. For each element i in nums, we insert i into the set and if i is greater than 0, we push it into the priority queue.\n1. We iterate through the priority queue. For each element x in the priority queue:\n - If the set contains -x, we return x as it satisfies the condition.\n- Otherwise, we pop the top element from the priority queue.\n4. If no such k is found, we return -1.\n\n# Complexity\n**Time complexity**:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n1. Let n be the size of the input array nums.\n1. Building the set and priority queue takes O(nlogn) time.\n1. The loop to check for the maximum k takes O(n) time in the worst case.\n1. Overall, the time complexity is O(nlogn).\n\n\n![upvote.png](https://assets.leetcode.com/users/images/2a16210b-be33-43ae-b22e-259595b7f631_1714612239.7901266.png)\n\n**Space complexity**:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n1. We use additional space for the priority queue and the set, both of which can store up to n elements.\n1. The space complexity is O(n).\n\n# Code\n```\nclass Solution {\npublic:\n    int findMaxK(vector<int>& nums) {\n        priority_queue<int> pq;\n        set<int> st;\n        for(auto i:nums){\n        st.insert(i);\n        if(i>0) pq.push(i);\n        }\n        while(!pq.empty()){\n            if(st.find(-pq.top())!=st.end()) return pq.top();\n            else pq.pop();\n        }\n        return -1;\n    }\n};\n```\nHappy Coding
['Array', 'Hash Table', 'Two Pointers', 'Sorting', 'C++']