[Java] TreeMap and PriorityQueue
\nclass Server {\n    int tr = 0; // Total Requests\n    int ft = 0; // Finishing Time\n    int index; // Server Index\n    \n    public Server(int index) {\n  
```\nclass Server {\n    int tr = 0; // Total Requests\n    int ft = 0; // Finishing Time\n    int index; // Server Index\n    \n    public Server(int index) {\n        this.index = index;\n    }\n    \n}\n\nclass Solution {\n    public List<Integer> busiestServers(int k, int[] arrival, int[] load) {\n       \n        TreeMap<Integer, Server> available = new TreeMap<>(); // Map of Available Servers\n        PriorityQueue<Server> busy = new PriorityQueue<>((Server a, Server b) -> {\n            return a.ft - b.ft;\n        });\n        List<Server> list = new ArrayList<>();\n        for(int i = 0; i < k; i++) {\n            Server server = new Server(i);\n            list.add(server);\n            available.put(i, server);\n        }\n       int max = 0;\n       for(int i = 0; i < arrival.length; i++) {\n            while(!busy.isEmpty() && busy.peek().ft <= arrival[i]){\n                Server server = busy.remove();\n                available.put(server.index, server);\n            }\n            if(available.size() == 0) continue;\n            int req = (i % k);\n            int serverIndex = -1;\n            if(available.ceilingKey(req) != null) serverIndex = available.ceilingKey(req);           \n            else serverIndex = available.firstKey();\n            Server server = available.get(serverIndex);\n            server.ft = arrival[i] + load[i];\n            server.tr += 1;\n            max = Math.max(max, server.tr);\n            busy.add(server);\n            available.remove(serverIndex);\n        }\n        List<Integer> result = new ArrayList<>();\n        for(int j =0; j < k; j++) {\n            if(list.get(j).tr == max) result.add(j);\n        }\n        return result;\n    }\n}\n```
[]