diff --git a/C++/1845-SeatReservationManager/Solution.cpp b/C++/1845-SeatReservationManager/Solution.cpp new file mode 100644 index 0000000..8cad920 --- /dev/null +++ b/C++/1845-SeatReservationManager/Solution.cpp @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +using namespace std; +class SeatManager { + private: + priority_queue, greater<>> availableSeats; + + public: + SeatManager(int n) { + for (int i = 1; i <= n; ++i) { + availableSeats.push(i); + } + } + + // Fetch smallest unreserved seat, reserves it and returns the number + int reserve() { + int smallestSeat = availableSeats.top(); + availableSeats.pop(); + return smallestSeat; + } + + // unreserves the seat with the given seatNumber + void unreserve(int seatNumber) { availableSeats.push(seatNumber); } +}; + +/** + * Your SeatManager object will be instantiated and called as such: + * SeatManager* obj = new SeatManager(n); + * int param_1 = obj->reserve(); + * obj->unreserve(seatNumber); + */ diff --git a/README.md b/README.md index d1d5ba2..02def96 100644 --- a/README.md +++ b/README.md @@ -340,6 +340,7 @@ Now solving in C++. Like it. | 1791 | FindCenterOfStarGraph | [![C++](assets/c++.svg)](C++/1791-FindCenterOfStarGraph/Solution.cpp) | | 1813 | SentenceSimilarityThree | [![C++](assets/c++.svg)](C++/1813-SentenceSimilarityThree/Solution.cpp) | | 1823 | FindTheWinnerOfTheCircularGame | [![C++](assets/c++.svg)](C++/1823-FindTheWinnerOfTheCircularGame/Solution.cpp) | +| 1845 | SeatReservationManager | [![C++](assets/c++.svg)](C++/1845-SeatReservationManager/Solution.cpp) | | 1863 | SumOfAllSubsetXORTotals | [![C++](assets/c++.svg)](C++/1863-SumOfAllSubsetXORTotals/Solution.cpp) | | 1884 | EggDropWith2EggsAndNFloors | [![Go](assets/go.svg)](Go/1884-EggDropWith2EggsAndNFloors/Solution.go) | | 1894 | FindTheStudentThatWillReplaceTheChalk | [![C++](assets/c++.svg)](C++/1894-FindTheStudentThatWillReplaceTheChalk/Solution.cpp) |