Top Company Trees and Tries Python practice problems
Cover the binary-tree, BST, trie, traversal, serialization, and path questions seen in coding loops.
Core concepts
Problem-solving patterns
- Choose DFS/BFS → define node state → combine child results
Reported company tags
All 20 problems in this topic
Work from top to bottom to build the concept gradually.
- #301Find lowest common ancestor: Targets in different subtreesCompany MediumPremium
Find the lowest node whose subtree contains both requested values.
- #302Find lowest common ancestor: One node is an ancestorCompany MediumPremium
Return the higher target when it already contains the other target.
- #303Find kth smallest value in a BST: Third smallestCompany MediumPremium
Return the third value in the BST's increasing order.
- #304Find kth smallest value in a BST: Smallest valueCompany MediumPremium
When k is one, return the minimum node.
- #305Serialize and deserialize a binary tree: Sparse tree round tripCompany HardPremium
Serialize a sparse tree, deserialize it, and show the preserved tokens.
- #306Serialize and deserialize a binary tree: Trim redundant trailing nullsCompany HardPremium
Remove trailing null markers that do not add structural information.
- #307Build a tree from preorder and inorder: Balanced reconstructionCompany MediumPremium
Reconstruct a tree and print its level-order values.
- #308Build a tree from preorder and inorder: Right-skewed reconstructionCompany MediumPremium
Build a tree whose nodes all lie on the right.
- #309View a binary tree from the right: Sparse right viewCompany MediumPremium
Return the node visible from the right at every tree level.
- #310View a binary tree from the right: Left-only treeCompany MediumPremium
A left child is visible when no node exists farther right on its level.
- #311Calculate binary-tree diameter: Diameter crosses rootCompany MediumPremium
Find the longest edge-count path between any two nodes.
- #312Calculate binary-tree diameter: Skewed treeCompany MediumPremium
The diameter of a one-sided chain is its number of edges.
- #313List root-to-leaf target paths: Two valid pathsCompany MediumPremium
List every root-to-leaf path whose values reach the target.
- #314List root-to-leaf target paths: No target pathCompany MediumPremium
Report None when no leaf completes the target sum.
- #315Implement a prefix trie: Word and prefix checksCompany MediumPremium
Insert words, then distinguish exact matches from valid prefixes.
- #316Implement a prefix trie: Missing prefixCompany MediumPremium
Return False when no inserted word begins with the requested prefix.
- #317Find dictionary words in a board: Several board wordsCompany HardPremium
Find all dictionary words that can be formed by adjacent cells without reuse.
- #318Find dictionary words in a board: No word can be formedCompany HardPremium
Report None when every dictionary word is impossible on the board.
- #319Find maximum binary-tree path sum: Best path crosses a subtree rootCompany HardPremium
Find the greatest sum along any connected path in the tree.
- #320Find maximum binary-tree path sum: All negative valuesCompany HardPremium
Choose the least negative single node when every extension would reduce the sum.