Java TreeSet with PriorityQueue w/ explanation
For each query, put all of the available servers at that point to the TreeSet, so that you can find the successor in O(log(k)) time. For tracking which all serv
For each query, put all of the available servers at that point to the TreeSet, so that you can find the successor in ```O(log(k))``` time. For tracking which all servers are available at the moment w/o going through the entire list, maintain a Min-Heap w.r.t finishing time, so that we can add them all to the TreeSet.\n```\nclass Solution \n{\n    public List<Integer> busiestServers(int k, int[] time, int[] load) \n    {\n        PriorityQueue<int[]> q=new PriorityQueue<int[]>((a,b)->((int[])a)[1]-((int[])b)[1]);\n        TreeSet<Integer> ptr=new TreeSet<Integer>();\n        for(int i=0;i<k;++i)\n            ptr.add(i);\n        int[] count=new int[k];\n        int val=0;\n        for(int i=0;i<time.length;++i)\n        {\n            while(!q.isEmpty()&&q.peek()[1]<=time[i])\n                ptr.add(q.poll()[0]);\n            int server=i%k;\n            int ret=-1;\n            if(ptr.isEmpty())\n                continue;\n            else if(ptr.contains(server))\n                ret=server;\n            else\n            {\n                Integer temp=ptr.higher(server);\n                if(temp!=null)\n                    ret=temp;\n                else\n                    ret=ptr.first();\n            }\n            if(ret!=-1)\n            {\n                val=Math.max(val,++count[ret]);\n                ptr.remove(ret);\n                q.add(new int[]{ret,time[i]+load[i]});\n            }\n        }\n        List<Integer> ret=new ArrayList<Integer>();\n        for(int i=0;i<k;++i)\n            if(count[i]==val)\n                ret.add(i);\n        return ret;\n    }\n}\n`````
['Tree', 'Heap (Priority Queue)', 'Ordered Set', 'Java']