JAVA EASY SOLUTION || TREEMAP || QUEUE
\nclass MKAverage {\n\n  int sum,total,m,k;\n\n    TreeMap<Integer,Integer> map=new TreeMap<>();\n    Queue<Integer> queue=new LinkedList<>();\n    public MKAve
```\nclass MKAverage {\n\n  int sum,total,m,k;\n\n    TreeMap<Integer,Integer> map=new TreeMap<>();\n    Queue<Integer> queue=new LinkedList<>();\n    public MKAverage(int m, int k) {\n\n       this.m=m;\n       this.k=k;\n    }\n\n    public void addElement(int num) {\n\n       total++;\n       sum+=num;\n       queue.add(num);\n       map.put(num,map.getOrDefault(num,0)+1);\n       if (total>m){\n           total--;\n          int first=queue.poll();\n          sum-=first;\n          if (map.get(first)==1)\n             map.remove(first);\n          else map.put(first,map.get(first)-1);\n\n       }\n\n\n    }\n\n    public int calculateMKAverage() {\n\n       if (total<m) return -1;\n\n       int count=k;\n       int temp_sum=sum;\n       for (Map.Entry<Integer,Integer> entry:map.entrySet()){\n          if (count==0) break;\n          int val=entry.getValue();\n          int key=entry.getKey();\n          int min=Math.min(count,val);\n          count-=min;\n          temp_sum-=min*key;\n\n       }\n       count=k;\n       for (Map.Entry<Integer,Integer> entry:map.descendingMap().entrySet()){\n          if (count==0) break;\n          int val=entry.getValue();\n          int key=entry.getKey();\n          int min=Math.min(count,val);\n          count-=min;\n          temp_sum-=min*key;\n       }\n\n\n       return temp_sum/(m-2*k);\n    }\n}\n```
[]