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

Stacks, Queues, Linked Lists, Trees, and Graphs Python practice problems

Implement the core data structures and traversal patterns behind many technical interviews.

20 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 cycleTraverse a binary tree by levelsFind binary-tree maximum depthValidate a binary search tree
REUSABLE THINKING

Problem-solving patterns

  • Choose the structure whose operations match the problem
INTERVIEW SIGNALS

Reported company tags

AmazonGoogleBloombergMicrosoftMetaUber
Community-reported tags are guidance, not guarantees.
ORDERED PRACTICE

All 20 problems in this topic

Work from top to bottom to build the concept gradually.

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

    Validate a correctly nested sequence of three bracket types.

    InterviewPremium
  2. #222
    Validate brackets with a stack: Wrong closing order

    Reject brackets that close in a different order from opening.

    InterviewPremium
  3. #223
    Implement a queue with two stacks: Normal queue commands

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

    InterviewPremium
  4. #224
    Implement a queue with two stacks: Empty queue

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

    InterviewPremium
  5. #225
    Reverse a linked list: Five-node list

    Reverse the links in a five-node chain.

    InterviewPremium
  6. #226
    Reverse a linked list: Single node

    A one-node linked list is unchanged by reversal.

    InterviewPremium
  7. #227
    Find the middle linked-list node: Odd-length list

    Return the central node from an odd number of nodes.

    InterviewPremium
  8. #228
    Find the middle linked-list node: Even-length convention

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

    InterviewPremium
  9. #229
    Detect a linked-list cycle: Cycle to second node

    Detect a tail that points back to an earlier node.

    InterviewPremium
  10. #230
    Detect a linked-list cycle: Acyclic chain

    Return False when the final next reference is None.

    InterviewPremium
  11. #231
    Traverse a binary tree by levels: Three-level tree

    Print each depth of a small complete tree on its own line.

    InterviewPremium
  12. #232
    Traverse a binary tree by levels: Single-node tree

    A one-node tree produces exactly one level.

    InterviewPremium
  13. #233
    Find binary-tree maximum depth: Unbalanced tree

    Find the depth of a tree whose longest path contains three nodes.

    InterviewPremium
  14. #234
    Find binary-tree maximum depth: Empty tree

    An empty tree represented by null has depth zero.

    InterviewPremium
  15. #235
    Validate a binary search tree: Valid BST

    Confirm that all nodes obey the global binary-search-tree ordering rule.

    InterviewPremium
  16. #236
    Validate a binary search tree: Hidden violation

    Detect a value that is locally plausible but violates an ancestor's bound.

    InterviewPremium
  17. #237
    Traverse a graph with BFS: Connected graph

    Visit a connected graph from vertex zero in deterministic neighbor order.

    InterviewPremium
  18. #238
    Traverse a graph with BFS: Disconnected graph

    Visit only the component reachable from the chosen start.

    InterviewPremium
  19. #239
    Find an unweighted shortest path: Route exists

    Find a shortest route in a small unweighted network.

    InterviewPremium
  20. #240
    Find an unweighted shortest path: Unreachable destination

    Report when start and target lie in disconnected components.

    InterviewPremium