Simple Easy to understand : can be mapped to many similar interval problems
Intuition\n-----\n\n(startTime,endTime) : already sorted\nPQ : for storing [endTime, serverSlot]\nTreeSet : - for storing availServers at any point in time\n\n-
# Intuition\n-----\n\n(startTime,endTime) : already sorted\n**PQ** : for storing [endTime, serverSlot]\n**TreeSet** : - for storing availServers at any point in time\n\n-------\n\n\n# Approach\n1. for each interval : (start,end)\n    1.1 remove all those from PQ which are already ended by now\n    1.2 add thier servers back to availServers list\n2. if no servers avail\n    2.1 dont assign this task\n2. if you have availServers:\n    2.1 fromlist of availServers\n    2.2 choose which server to assign this job to\n    2.3 given constraint is to choose first : i%k if avail\n    2.4 if not : choose next (i%k+1)..(i%k+2) ..etc \n    2.5 here, we will take advantage of TreeSet : ceiling function\n    2.6 we dont have to iterate circular over the nextAvail\n    2.7 once found : assign this job to server and remove from availServer\n3. during the prorcess: keep track of maxCount of jobs for each server\n4. return all that has maxJobsSchedule\n\n# Complexity\n- Time complexity:\nO(n log n) : for PQ\nO(n log n) : for TreeSet\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution {\n    public List<Integer> busiestServers(int k, int[] arrival, int[] load) {\n        \n        //arrival is time of arrival : load is the time taken\n        //lets make a pair [startTime, endTime=(startTime+load)]\n        PriorityQueue<int[]>pq=new PriorityQueue<>((a,b)->a[0]-b[0]);\n        TreeSet<Integer>avail=new TreeSet<>();\n        for(int i=0;i<k;i++)\n         avail.add(i);\n        \n        int[]count=new int[k];\n        int maxSlot = 0;\n\n        for(int i=0;i<arrival.length;i++){\n            int start = arrival[i];\n            int end = start+load[i];\n\n            //remove all tasks which are over earlier or just now at this start time\n            // keep adding back the servers free to avail list\n            while(!pq.isEmpty() && pq.peek()[0]<=start){\n\n                int[]rm=pq.remove();\n                avail.add(rm[1]);\n                \n            }\n            //we need to have slot avail to assign the task to the server\n            if(!avail.isEmpty()){\n                //a.ask is if i%k is avail assign that\n                Integer slot = avail.ceiling(i%k);\n\n                //b.if not -> circular next avail : since treeSet ceiling will give next slot for key = i%k\n                //if none => we circle back from start : so first avail slot is what is we need\n                if(slot ==null ){\n                    slot = avail.first();\n                }\n                \n                \n                pq.add(new int[]{end,slot});\n                avail.remove(slot);\n                count[slot]++;\n                maxSlot=Math.max(count[slot],maxSlot);\n            }\n\n        }\n\n        List<Integer>res=new ArrayList<>();\n        for(int i=0;i<k;i++){\n            if(count[i]==maxSlot)\n                res.add(i);\n        }\n        return res;\n    }\n}\n```
['Java']