Question 1:
Bob is planning to learn music and lose weight. He has to plan for his next n days.
For the i-th day there are four options:
gym is closed and the music class is off.
gym is closed and the music class is on.
gym is open and the music class is off.
gym is open and the music class is on.
On each of the days, Bob can either have a rest or join music class, or do workout
Find the minimum number of days on which Bob will have to rest (it means, he will not do workout and attend music class at the same time). He does not want to do the same activity on two consecutive days: it means, he will not do workout on two consecutive days and join music class on two consecutive days.
Input
The first line contains a positive integer n - the number of days
The second line contains the sequence of integers a1, a2, ..., an (0 ≤ ai ≤ 3)
ai equals 0, if on the i-th day the gym is closed and the music class is off.
ai equals 1, if on the i-th day the gym is closed, but the music class is on.
ai equals 2, if on the i-th day the gym is open and the music class is off.
ai equals 3, if on the i-th day the gym is open and the music class is on.
Test Cases:
Input
4
1 3 2 0
Output
2
Input
7
1 3 3 2 1 2 3
output
0
input
2
2 2
output
1
Question 2:
Design a seat reservation system. seats are numbered from 1 to n.
Implement the SeatManager class:
SeatManager(int n) Initializes a SeatManager object that will manage n seats numbered from 1 to n. All seats are initially available.
int reserve() Fetches the smallest-numbered unreserved seat, reserves it, and returns its number.
void unreserve(int seatNumber) Unreserves the seat with the given seatNumber.
Example 1:
Input
["SeatManager(5)", "reserve", "reserve", "unreserve(2)", "reserve", "reserve", "reserve", "reserve", "unreserve(5)"]
Output
[null, 1, 2, null, 2, 3, 4, 5, null]
Solution1:
