pyPython Practice LabFrom first print to final round
TOPIC 14 OF 18

Core Data Structures: Stacks, Queues, Linked Lists, Heaps, and Intervals Python practice problems

Choosing structures by operations, monotonic reasoning, priority queues, and interval processing.

30 exercises8+ conceptsBeginner → interview context
Start this topic
WHAT YOU WILL PRACTISE

Core concepts

Validate brackets with a stackImplement a queue with two stacksReverse a linked listFind the middle linked-list nodeDetect a linked-list cycleMerge k sorted listsAdd numbers stored in linked listsCopy a random-pointer list
REUSABLE THINKING

Problem-solving patterns

  • stack · common interview
  • queue · two stacks
  • linked list · pointers
  • fast slow pointers · linked list
  • Floyd cycle · linked list
PRACTICE OUTCOME

What this topic builds

Learn the idea once, use it across the exercises, and explain why your approach works.

ORDERED PRACTICE

All 30 problems in this topic

Work from top to bottom to build the concept gradually.

  1. #243
    Validate brackets with a stack: Nested expression

    Validate a correctly nested sequence of three bracket types.

    BeginnerPremium
  2. #244
    Validate brackets with a stack: Wrong closing order

    Reject brackets that close in a different order from opening.

    BeginnerPremium
  3. #245
    Implement a queue with two stacks: Normal queue commands

    Process enqueues, a peek, and removals in first-in-first-out order.

    IntermediatePremium
  4. #246
    Implement a queue with two stacks: Empty queue

    Return Empty when a removal is requested with no queued items.

    IntermediatePremium
  5. #247
    Reverse a linked list: Five-node list

    Reverse the links in a five-node chain.

    IntermediatePremium
  6. #248
    Reverse a linked list: Single node

    A one-node linked list is unchanged by reversal.

    IntermediatePremium
  7. #249
    Find the middle linked-list node: Odd-length list

    Return the central node from an odd number of nodes.

    IntermediatePremium
  8. #250
    Find the middle linked-list node: Even-length convention

    For an even list, return the second of the two middle nodes.

    AdvancedPremium
  9. #251
    Detect a linked-list cycle: Cycle to second node

    Detect a tail that points back to an earlier node.

    AdvancedPremium
  10. #252
    Detect a linked-list cycle: Acyclic chain

    Return False when the final next reference is None.

    AdvancedPremium
  11. #253
    Merge k sorted lists: Three sorted feeds

    Merge three sorted integer feeds into one ordered stream.

    AdvancedPremium
  12. #254
    Merge k sorted lists: Single source

    With one source, the heap returns the original sorted sequence.

    AdvancedPremium
  13. #255
    Add numbers stored in linked lists: Different three-digit numbers

    Add two numbers whose digits are stored least-significant first.

    AdvancedPremium
  14. #256
    Add numbers stored in linked lists: Carry creates a new digit

    Continue after both lists end when a final carry remains.

    AdvancedPremium
  15. #257
    Copy a random-pointer list: Mixed random links

    Deep-copy a list whose random pointers target several nodes.

    Interview-LevelPremium
  16. #258
    Copy a random-pointer list: No random links

    Copy a list where every random pointer is None.

    Interview-LevelPremium
  17. #259
    Reorder a linked list: Even-length chain

    Reorder nodes as first, last, second, second-last, and so on.

    Interview-LevelPremium
  18. #260
    Reorder a linked list: Odd-length chain

    Leave the middle node for the final position in an odd-length list.

    Interview-LevelPremium
  19. #261
    Implement an LRU cache: Evict old entries

    Process cache operations and evict the least recently used key at capacity.

    Interview-LevelPremium
  20. #262
    Implement an LRU cache: Refresh an existing key

    Updating an existing key also makes it most recently used.

    Interview-LevelPremium
  21. #263
    Implement a minimum stack: Track changing minimums

    Return the current minimum as values are pushed and removed.

    Interview-LevelPremium
  22. #264
    Implement a minimum stack: Duplicate minimum

    Keep the correct minimum when one of two equal minimum values is popped.

    Interview-LevelPremium
  23. #265
    Find warmer-day waits: Mixed forecast

    For each day, count how long until a warmer temperature appears.

    Interview-LevelPremium
  24. #266
    Find warmer-day waits: Never warmer

    All waits are zero when temperatures only decrease.

    Interview-LevelPremium
  25. #267
    Find the largest histogram rectangle: Classic histogram

    Find the maximum rectangle area in a varied histogram.

    Interview-LevelPremium
  26. #268
    Find the largest histogram rectangle: Uniform bars

    Use the full width when every bar has the same height.

    Interview-LevelPremium
  27. #269
    Find sliding-window maximums: Overlapping windows

    Return the maximum from every width-three sliding window.

    Interview-LevelPremium
  28. #270
    Find sliding-window maximums: Window of one

    A window of one returns every original value.

    Interview-LevelPremium
  29. #271
    Count required meeting rooms: Overlapping meetings

    Find how many rooms are needed so no meeting is delayed.

    Interview-LevelPremium
  30. #272
    Count required meeting rooms: Back-to-back meetings

    Reuse one room when each meeting ends as the next begins.

    Interview-LevelPremium