MinHeap + Map | Easily understandable commented code | C++ | Faster than 90%
Intuition\n Describe your first thoughts on how to solve this problem. \nThere are few smart decisions that we need to make\n1. Choosing set over vection for ma
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThere are few smart decisions that we need to make\n1. Choosing set over vection for maintaining availaible servers, so that we can use the power of lower_bound directly to get the next availaible server faster (instead of linearly scanning over the next availaible server)\n2. Using priority queue(min heap on ending time) for busy servers. \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> busiestServers(int k, vector<int>& arrival, vector<int>& load) {\n        set <int> availaible; // We are using set to maintain currently availaible servers\n        for(int i=0;i<k;i++) availaible.insert(i); // Currently all servers are availaible\n\n        vector <int> usedCount(k,0); // Used to maintain how many times given server is used\n        priority_queue <pair <int,int>,vector <pair <int,int>>, greater <pair <int,int>>> busy; // end time,server id -> min queue\n        \n        for(int i=0;i<arrival.size();i++){\n            // Making busy servers availaible whose endTime is less than current time (arrival time) \n            while(!busy.empty() && arrival[i]>=busy.top().first){\n                availaible.insert(busy.top().second);\n                busy.pop();\n            }\n\n            // Checking if any server is availaible, and making the candidate server busy\n            if(availaible.size()){\n                auto server = availaible.lower_bound(i%k);\n                if(server==availaible.end()){\n                    server = availaible.begin();\n                }\n                int serverId = *server;\n                availaible.erase(server);\n                int endTime = arrival[i]+load[i];\n                usedCount[serverId]++;\n                busy.push({endTime,serverId}); \n            }\n        }\n\n        // Finding the maximum number of time any server is used \n        int mx = *max_element(usedCount.begin(),usedCount.end());\n        // Adding servers in ans\n        vector <int> ans;\n        for(int i=0;i<usedCount.size();i++){\n            if(usedCount[i]==mx){\n                ans.push_back(i);\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']