All problems

Problem 593

Design Circular Queue

Medium · 20 pts · Queue, Design, Array

Problem

Simulate a circular queue with a fixed capacity K. 'enQueue x' adds x at the rear and prints true, or prints false if the queue is full. 'deQueue' removes the front element and prints true, or prints false if the queue is empty. 'Front' and 'Rear' print the front and rear element, or -1 if the queue is empty. 'isEmpty' and 'isFull' print true or false. Use an array of size K with a head index and a count, wrapping indices with modulo K.

Input

The first line contains K and Q. Each of the next Q lines contains one operation.

Output

Print one line for each operation with its result.

Constraints

1 <= K <= 1000; 1 <= Q <= 3000; 0 <= x <= 1000

Example input

3 9
enQueue 1
enQueue 2
enQueue 3
enQueue 4
Rear
isFull
deQueue
enQueue 4
Rear

Example output

true
true
true
false
3
true
true
true
4

Explanation

With K = 3: three enQueues succeed (true), the fourth fails (false). Rear is 3, isFull is true, deQueue succeeds, enQueue 4 now fits, and Rear becomes 4.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Exclusive Time of Functions Next: LRU Cache