✅ Easy and Intuitive solution | ✅ Priority_queue used | cpp ✅
Intuition\n Describe your first thoughts on how to solve this problem. \nIt is a hard problem but we can simply use 2 heaps i.e. there will be 2 cases .\nGiven 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIt is a hard problem but we can simply use 2 heaps i.e. there will be 2 cases .\nGiven question asks us to get the median of the given stream of inputs right. So we have 2 cases -\n1.Even number of inputs given\n2.Odd number of inputs given\n\n\nSo, for even number of inputs we understand that there will be 2 middle elements (say n elements are there so we add element(n/2)+element(n-1/2)) and then average them and return it.\n\nFor odd , number of elements of inputs its simpler, as we just return the element(n/2)[considering there are n total elements]\n\nNow what we do is we maintain 2 heaps --> a left max-heap and a right min-heap\nwhat we will do is we will keep adding elements to the left max-heap unless the current input element is greater than the max-heap\'s top element which we will then push in the right heap. But we will also check one condition here --> the difference in the size of the 2 heaps shall not increase more than 1 and also we need to maintain them in such a way that the left heap has always, if n is odd , one extra element than the right min-heap. You will get it once u dry run this with some example.\n\nRest you can see the code yourself and see I have just returned the answer as per the conditions.\n\nHope the implementation is easy :)\n# Approach\n<!-- Describe your approach to solving the problem. -->\n2 heaps taken for input --->\n1. left-min-heap\n2. right-max-heap\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(LogN)ForAddnum\nO(1)ForFindmedian\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(N)\n# Code\n```\nclass MedianFinder {\npublic:\n    priority_queue<int> left_max_heap; // max heap\n    priority_queue<int, vector<int>,greater<int>> right_min_heap; // min heap\n    MedianFinder() {\n        \n    }\n    \n    void addNum(int num) {\n        if(left_max_heap.empty() || num<left_max_heap.top()){\n            left_max_heap.push(num);\n        }else{\n            right_min_heap.push(num);\n        }\n        //always maintain left max heap size >= right min heap\n        if(abs((int)left_max_heap.size() - (int)right_min_heap.size()) > 1){\n            right_min_heap.push(left_max_heap.top());\n            left_max_heap.pop();\n        }else if(left_max_heap.size()<right_min_heap.size()){\n            left_max_heap.push(right_min_heap.top());\n            right_min_heap.pop();\n        }\n    }\n    \n    double findMedian() {\n        if(left_max_heap.size()==right_min_heap.size()){\n            return (double)(left_max_heap.top()+right_min_heap.top())/2;\n        }\n        return left_max_heap.top();\n    }\n};\n```\n\n![upvote_pic.webp](https://assets.leetcode.com/users/images/588ad83f-3752-42e9-bd40-7b8f913695b7_1723988192.028273.webp)\n
['C++']