We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
class Solution { public: int smallestChair(vector<vector<int>>& times, int targetFriend) { int n = times.size(); vector<int> order(n); for (int i = 0; i < n; i++) order[i] = i; sort(order.begin(), order.end(), [×](int a, int b) { return times[a][0] < times[b][0]; }); priority_queue<int, vector<int>, greater<int>> emptySeats; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> takenSeats; for (int i = 0; i < n; i++) emptySeats.push(i); for (int i : order) { int arrival = times[i][0], leave = times[i][1]; while (!takenSeats.empty() && takenSeats.top().first <= arrival) { emptySeats.push(takenSeats.top().second); takenSeats.pop(); } int seat = emptySeats.top(); emptySeats.pop(); if (i == targetFriend) return seat; takenSeats.push({leave, seat}); } return -1; } };
The text was updated successfully, but these errors were encountered:
fkdl0048
No branches or pull requests
The text was updated successfully, but these errors were encountered: