Stacks, Queues, Linked Lists, Trees, and Graphs Python practice problems
Implement the core data structures and traversal patterns behind many technical interviews.
Core concepts
Problem-solving patterns
- Choose the structure whose operations match the problem
Reported company tags
All 20 problems in this topic
Work from top to bottom to build the concept gradually.
- #221Validate brackets with a stack: Nested expressionInterviewPremium
Validate a correctly nested sequence of three bracket types.
- #222Validate brackets with a stack: Wrong closing orderInterviewPremium
Reject brackets that close in a different order from opening.
- #223Implement a queue with two stacks: Normal queue commandsInterviewPremium
Process enqueues, a peek, and removals in first-in-first-out order.
- #224Implement a queue with two stacks: Empty queueInterviewPremium
Return Empty when a removal is requested with no queued items.
- #225Reverse a linked list: Five-node listInterviewPremium
Reverse the links in a five-node chain.
- #226Reverse a linked list: Single nodeInterviewPremium
A one-node linked list is unchanged by reversal.
- #227Find the middle linked-list node: Odd-length listInterviewPremium
Return the central node from an odd number of nodes.
- #228Find the middle linked-list node: Even-length conventionInterviewPremium
For an even list, return the second of the two middle nodes.
- #229Detect a linked-list cycle: Cycle to second nodeInterviewPremium
Detect a tail that points back to an earlier node.
- #230Detect a linked-list cycle: Acyclic chainInterviewPremium
Return False when the final next reference is None.
- #231Traverse a binary tree by levels: Three-level treeInterviewPremium
Print each depth of a small complete tree on its own line.
- #232Traverse a binary tree by levels: Single-node treeInterviewPremium
A one-node tree produces exactly one level.
- #233Find binary-tree maximum depth: Unbalanced treeInterviewPremium
Find the depth of a tree whose longest path contains three nodes.
- #234Find binary-tree maximum depth: Empty treeInterviewPremium
An empty tree represented by null has depth zero.
- #235Validate a binary search tree: Valid BSTInterviewPremium
Confirm that all nodes obey the global binary-search-tree ordering rule.
- #236Validate a binary search tree: Hidden violationInterviewPremium
Detect a value that is locally plausible but violates an ancestor's bound.
- #237Traverse a graph with BFS: Connected graphInterviewPremium
Visit a connected graph from vertex zero in deterministic neighbor order.
- #238Traverse a graph with BFS: Disconnected graphInterviewPremium
Visit only the component reachable from the chosen start.
- #239Find an unweighted shortest path: Route existsInterviewPremium
Find a shortest route in a small unweighted network.
- #240Find an unweighted shortest path: Unreachable destinationInterviewPremium
Report when start and target lie in disconnected components.