Core Data Structures: Stacks, Queues, Linked Lists, Heaps, and Intervals Python practice problems
Choosing structures by operations, monotonic reasoning, priority queues, and interval processing.
Core concepts
Problem-solving patterns
- stack · common interview
- queue · two stacks
- linked list · pointers
- fast slow pointers · linked list
- Floyd cycle · linked list
What this topic builds
Learn the idea once, use it across the exercises, and explain why your approach works.
All 30 problems in this topic
Work from top to bottom to build the concept gradually.
- #243Validate brackets with a stack: Nested expressionBeginnerPremium
Validate a correctly nested sequence of three bracket types.
- #244Validate brackets with a stack: Wrong closing orderBeginnerPremium
Reject brackets that close in a different order from opening.
- #245Implement a queue with two stacks: Normal queue commandsIntermediatePremium
Process enqueues, a peek, and removals in first-in-first-out order.
- #246Implement a queue with two stacks: Empty queueIntermediatePremium
Return Empty when a removal is requested with no queued items.
- #247Reverse a linked list: Five-node listIntermediatePremium
Reverse the links in a five-node chain.
- #248Reverse a linked list: Single nodeIntermediatePremium
A one-node linked list is unchanged by reversal.
- #249Find the middle linked-list node: Odd-length listIntermediatePremium
Return the central node from an odd number of nodes.
- #250Find the middle linked-list node: Even-length conventionAdvancedPremium
For an even list, return the second of the two middle nodes.
- #251Detect a linked-list cycle: Cycle to second nodeAdvancedPremium
Detect a tail that points back to an earlier node.
- #252Detect a linked-list cycle: Acyclic chainAdvancedPremium
Return False when the final next reference is None.
- #253Merge k sorted lists: Three sorted feedsAdvancedPremium
Merge three sorted integer feeds into one ordered stream.
- #254Merge k sorted lists: Single sourceAdvancedPremium
With one source, the heap returns the original sorted sequence.
- #255Add numbers stored in linked lists: Different three-digit numbersAdvancedPremium
Add two numbers whose digits are stored least-significant first.
- #256Add numbers stored in linked lists: Carry creates a new digitAdvancedPremium
Continue after both lists end when a final carry remains.
- #257Copy a random-pointer list: Mixed random linksInterview-LevelPremium
Deep-copy a list whose random pointers target several nodes.
- #258Copy a random-pointer list: No random linksInterview-LevelPremium
Copy a list where every random pointer is None.
- #259Reorder a linked list: Even-length chainInterview-LevelPremium
Reorder nodes as first, last, second, second-last, and so on.
- #260Reorder a linked list: Odd-length chainInterview-LevelPremium
Leave the middle node for the final position in an odd-length list.
- #261Implement an LRU cache: Evict old entriesInterview-LevelPremium
Process cache operations and evict the least recently used key at capacity.
- #262Implement an LRU cache: Refresh an existing keyInterview-LevelPremium
Updating an existing key also makes it most recently used.
- #263Implement a minimum stack: Track changing minimumsInterview-LevelPremium
Return the current minimum as values are pushed and removed.
- #264Implement a minimum stack: Duplicate minimumInterview-LevelPremium
Keep the correct minimum when one of two equal minimum values is popped.
- #265Find warmer-day waits: Mixed forecastInterview-LevelPremium
For each day, count how long until a warmer temperature appears.
- #266Find warmer-day waits: Never warmerInterview-LevelPremium
All waits are zero when temperatures only decrease.
- #267Find the largest histogram rectangle: Classic histogramInterview-LevelPremium
Find the maximum rectangle area in a varied histogram.
- #268Find the largest histogram rectangle: Uniform barsInterview-LevelPremium
Use the full width when every bar has the same height.
- #269Find sliding-window maximums: Overlapping windowsInterview-LevelPremium
Return the maximum from every width-three sliding window.
- #270Find sliding-window maximums: Window of oneInterview-LevelPremium
A window of one returns every original value.
- #271Count required meeting rooms: Overlapping meetingsInterview-LevelPremium
Find how many rooms are needed so no meeting is delayed.
- #272Count required meeting rooms: Back-to-back meetingsInterview-LevelPremium
Reuse one room when each meeting ends as the next begins.