DEV Community

Harsh Mishra
Harsh Mishra

Posted on

Queues: 50 Leetcode Questions

Top 50 Must-Do LeetCode Questions on Queues for Your Coding Interview Preparation

Queues are an essential data structure used in many real-world applications like scheduling, breadth-first search (BFS), and more. Below is a curated list of 50 queue-related LeetCode problems divided into Easy, Medium, and Hard categories, along with a brief two-liner description of each.


Easy Questions (20 Questions)

  1. Implement Queue using Stacks (232)

    Implement a queue using two stacks to handle enqueue and dequeue operations.

  2. Design Circular Queue (622)

    Design a circular queue supporting efficient operations with a fixed capacity.

  3. Moving Average from Data Stream (346)

    Maintain a moving average of integers from a data stream using a fixed-size queue.

  4. Number of Recent Calls (933)

    Count the number of calls received within a given time frame using a sliding window.

  5. First Unique Character in a String (387)

    Find the first non-repeating character in a string using a queue.

  6. Perfect Squares (279)

    Find the least number of perfect square numbers that sum up to a given number using BFS.

  7. Open the Lock (752)

    Find the minimum steps to unlock a combination lock using BFS.

  8. Rotting Oranges (994)

    Determine the minimum time to rot all oranges in a grid using multi-source BFS.

  9. Binary Tree Level Order Traversal (102)

    Perform a level-order traversal of a binary tree using a queue.

  10. Symmetric Tree (101)

    Check if a binary tree is symmetric using BFS with a queue.

  11. Shortest Path in Binary Matrix (1091)

    Find the shortest path from the top-left to the bottom-right in a binary grid.

  12. Walls and Gates (286)

    Fill each empty room with the distance to its nearest gate using multi-source BFS.

  13. Island Perimeter (463)

    Calculate the perimeter of an island represented in a grid.

  14. Breadth-First Search Traversal

    Implement BFS traversal for a graph using a queue.

  15. Time Needed to Inform All Employees (1376)

    Find the time required to inform all employees in a hierarchy using BFS.

  16. Course Schedule (207)

    Check if all courses can be finished given prerequisites using topological sorting.

  17. Flood Fill (733)

    Perform a flood-fill operation on a grid using BFS.

  18. Snakes and Ladders (909)

    Find the minimum moves to reach the last square in a snakes and ladders game.

  19. Binary Tree Zigzag Level Order Traversal (103)

    Traverse a binary tree in a zigzag level order using a queue.

  20. Sliding Window Maximum (239)

    Find the maximum value in each sliding window of size k.


Medium Questions (25 Questions)

  1. Design Front Middle Back Queue (1670)

    Implement a double-ended queue with front, middle, and back operations.

  2. Top K Frequent Elements (347)

    Find the top k most frequent elements in an array using a priority queue.

  3. Find the Winner of the Circular Game (1823)

    Simulate a circular game using a queue to determine the winner.

  4. Jump Game VI (1696)

    Find the maximum score you can achieve in a jump game with a sliding window queue.

  5. Course Schedule II (210)

    Find the order of courses to finish all given prerequisites using BFS.

  6. K Closest Points to Origin (973)

    Find the k closest points to the origin using a priority queue.

  7. Task Scheduler (621)

    Schedule tasks with cooling intervals using a queue.

  8. Reorganize String (767)

    Rearrange a string so that no two adjacent characters are the same using a priority queue.

  9. Sum of Subarray Minimums (907)

    Calculate the sum of minimum values of all subarrays using monotonic queues.

  10. Cheapest Flights Within K Stops (787)

    Find the cheapest flight route with at most k stops using a queue for BFS.

  11. Reach a Number (754)

    Find the minimum steps to reach a target number starting from zero.

  12. Count Complete Tree Nodes (222)

    Count the number of nodes in a complete binary tree using BFS.

  13. Shortest Bridge (934)

    Find the shortest bridge between two islands using BFS.

  14. Remove All Adjacent Duplicates in String II (1209)

    Remove adjacent duplicates in a string with a stack-queue hybrid approach.

  15. Kth Largest Element in a Stream (703)

    Find the kth largest element from a dynamic data stream.

  16. Escape the Spreading Fire (2428)

    Determine the earliest escape time given fire spreading on a grid.

  17. Data Stream as Disjoint Intervals (352)

    Add intervals from a stream and return a disjoint set of intervals.

  18. Sliding Puzzle (773)

    Solve a sliding puzzle using BFS to reach the goal state.

  19. Maximum Performance of a Team (1383)

    Select a team to maximize performance using a priority queue.

  20. Sequential Digits (1291)

    Generate numbers with sequential digits in a given range using BFS.

  21. The Maze (490)

    Determine if the ball can stop at the destination in a maze using BFS.

  22. Find Eventual Safe States (802)

    Find nodes in a graph that are eventually safe using BFS.

  23. Kill Process (582)

    Kill a process and its children given a parent-child relationship.

  24. Employee Importance (690)

    Calculate the total importance of an employee and their subordinates.

  25. Design Hit Counter (362)

    Count the number of hits in a given time frame using a sliding window queue.


Hard Questions (5 Questions)

  1. Minimum Cost to Connect Sticks (1167)

    Connect sticks of varying lengths with the minimum cost using a priority queue.

  2. Merge k Sorted Lists (23)

    Merge k sorted linked lists into one sorted list using a priority queue.

  3. LFU Cache (460)

    Design an LFU (Least Frequently Used) cache with efficient operations.

  4. Minimum Number of Refueling Stops (871)

    Determine the minimum number of refueling stops to reach a target.

  5. Swim in Rising Water (778)

    Find the minimum time to swim from the top-left to the bottom-right in a grid.


By practicing these queue-related problems, you’ll develop a solid understanding of queue operations and their real-world applications. Which one are you solving first?

Top comments (0)