I have a Data Structure question where I need to manage an hotel, each room has a number between $1-n$
and it can be occupied or not.
Available Data structures: AVL* Trees, B-Trees, Arrays, Stacks, Queues, Binary Trees.
$O(n)$ Space complexity available.
Using AVL OR B-Tree is a must.
I have to support these functions:
1) $\text{Init(n)}$ : Initializes the data structure with $n$ unoccupied rooms, the indexing of the rooms is $1-n$
this has to work at $O(n)$ time complexity
For the next functions: $l$ and $r$ do not have to be a number of an occupied room-
2) $\text{GetUnOcc(l,r)}$ : Gets $l$ -Left and $r$ - Right (Does not have to be an occupied room number) , 2 numbers that defined a range of numbers and I need to count how many hotel rooms are not occupied between them (Including). Has to work at $O(\log_2{n})$ Time complexity
3) $\text{GetMinUnOcc(l,r})$ : Gets $l$-Left and $r$-Right, 2 numbers that define a range of numbers, this one adds the person to the hotel at the smallest room that is not yet occupied between $l-r$ (Including).
Has to work at $O(\log_2{n})$ Time complexity
4) $\text{GetOut(r)}$ : It gets a room number and deletes the person from that Room/Hotel, making room number $r$ unoccupied.
Has to work at $O(\log_2{n})$ Time complexity
My Go:
Init: I thought about using an AVL tree with a boolean array.
We initialize it $O(n)$ by just making an array of False (Unoccupied) which takes $O(n)$
GetUnOcc(l,r) : I thought about this formula:
$\text{#UnOcc} = r - l + 1 - \text{Occupied}$ so we need to find how many rooms are occupied between $l-r$ but I am not sure how to do so in $O(\log_2{n})$
GetMinUnOcc is much harder because I cannot determine which value is the smallest, let's say $l=3$ and $r=10$ and every room between $3-8$ and room $10$ are occupied, and I need to return $9$ (because it is the smallest which is not occupied)
Let's say I have this tree (as Steven suggested to build an AVL of unoccupied rooms) so in this matter it is $\text{Init(10)}$ And Now I want to do $\text{GetMinUnOcc(5,7)}$ so it should delete $5$ from the tree as it will become occupied. But in what you suggest, we find the successor of $l=5$ which is his parent, $6$ and delete it, but, $5$ is not occupied and we want to return the minimum so we need to actually delete $5$, where am I wrong? Thank you!

I would appreciate your help / hints to solve this hard question! Thank you!
