Easy Java Solution using Priority Queue With Detailed Explanation
Please Upvote if you liked the post\n\n\nclass MedianFinder {\n     PriorityQueue<Integer> left;\n     PriorityQueue<Integer> right;\n\n    /** initialize your 
**Please Upvote if you liked the post**\n\n```\nclass MedianFinder {\n     PriorityQueue<Integer> left;\n     PriorityQueue<Integer> right;\n\n    /** initialize your data structure here. */\n    public MedianFinder() {\n         left = new PriorityQueue<>(Collections.reverseOrder()); //max priority Q\n         right = new PriorityQueue<>(); //min priority Q\n\n    }\n    \n    public void addNum(int val) {\n           if(right.size() > 0 && val > right.peek()){\n            right.add(val);\n          }else{\n              left.add(val);\n          }\n            //balancing elements in both priority q logic\n        \n          if(right.size() - left.size() == 2){  //right has more elements\n              left.add(right.remove());\n          }else if(left.size() - right.size() == 2){\n              right.add(left.remove());\n          }\n\n    }\n    \n    public double findMedian() {\n        if(left.size() == right.size()){\n              return ((double)left.peek() + (double)right.peek()) / 2;\n          }else if(left.size() > right.size()){\n            return (double)left.peek();\n        }else{                                //right.size() > left.size();\n              return (double)right.peek();\n          }\n    }\n}\n\n/**\n We want that either size of left and right priority Q is same if yes then median is\n (leftpeek + rightpeek) /2 because left priority Q stores max element and right\n priorityQ stores min element , so these peeks contains 2 adjacent elements required\n for even size median.\n \n if size is odd then one priority q will have extra element , one has n elements and other has n + 1 element , so median will be  from peek of  (n + 1 Size) priority Q\'s.\n \n We don\'t want difference of size more than one . so if difference of size becomes 2 we have to balance it , then only we can get our median.\n */\n```
['Heap (Priority Queue)', 'Java']