Understanding FIFO queues and double-ended queues (Deques).
A Queue is a linear data structure that adheres to the First-In, First-Out (FIFO) principle. Elements are added at one end, called the rear, and removed from the other end, called the front. The primary operations are `enqueue` (add to rear) and `dequeue` (remove from front). Queues are ideal for managing tasks or requests in the order they are received, such as a print queue or requests to a web server. They are also the core data structure used in Breadth-First Search (BFS) graph traversal. A Deque, or double-ended queue, is a generalization of a queue. It allows for efficient insertion and deletion of elements from both the front and the back. This makes it a very versatile data structure. It can be used as a stack (by only using `push_back` and `pop_back`) or as a queue (by using `push_back` and `pop_front`). Its true power comes from the ability to mix and match these operations. Deques are often used in algorithms where elements need to be added or removed from both ends, such as certain sliding window problems (e.g., finding the maximum in every window of size k), where we need to maintain a window of candidates and efficiently remove elements from both the front and back.