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

Top Company Trees and Tries Python practice problems

Cover the binary-tree, BST, trie, traversal, serialization, and path questions seen in coding loops.

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

Core concepts

Find lowest common ancestorFind kth smallest value in a BSTSerialize and deserialize a binary treeBuild a tree from preorder and inorderView a binary tree from the rightCalculate binary-tree diameterList root-to-leaf target pathsImplement a prefix trie
REUSABLE THINKING

Problem-solving patterns

  • Choose DFS/BFS → define node state → combine child results
INTERVIEW SIGNALS

Reported company tags

AmazonMicrosoftGoogleMeta
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. #301
    Find lowest common ancestor: Targets in different subtrees

    Find the lowest node whose subtree contains both requested values.

    Company MediumPremium
  2. #302
    Find lowest common ancestor: One node is an ancestor

    Return the higher target when it already contains the other target.

    Company MediumPremium
  3. #303
    Find kth smallest value in a BST: Third smallest

    Return the third value in the BST's increasing order.

    Company MediumPremium
  4. #304
    Find kth smallest value in a BST: Smallest value

    When k is one, return the minimum node.

    Company MediumPremium
  5. #305
    Serialize and deserialize a binary tree: Sparse tree round trip

    Serialize a sparse tree, deserialize it, and show the preserved tokens.

    Company HardPremium
  6. #306
    Serialize and deserialize a binary tree: Trim redundant trailing nulls

    Remove trailing null markers that do not add structural information.

    Company HardPremium
  7. #307
    Build a tree from preorder and inorder: Balanced reconstruction

    Reconstruct a tree and print its level-order values.

    Company MediumPremium
  8. #308
    Build a tree from preorder and inorder: Right-skewed reconstruction

    Build a tree whose nodes all lie on the right.

    Company MediumPremium
  9. #309
    View a binary tree from the right: Sparse right view

    Return the node visible from the right at every tree level.

    Company MediumPremium
  10. #310
    View a binary tree from the right: Left-only tree

    A left child is visible when no node exists farther right on its level.

    Company MediumPremium
  11. #311
    Calculate binary-tree diameter: Diameter crosses root

    Find the longest edge-count path between any two nodes.

    Company MediumPremium
  12. #312
    Calculate binary-tree diameter: Skewed tree

    The diameter of a one-sided chain is its number of edges.

    Company MediumPremium
  13. #313
    List root-to-leaf target paths: Two valid paths

    List every root-to-leaf path whose values reach the target.

    Company MediumPremium
  14. #314
    List root-to-leaf target paths: No target path

    Report None when no leaf completes the target sum.

    Company MediumPremium
  15. #315
    Implement a prefix trie: Word and prefix checks

    Insert words, then distinguish exact matches from valid prefixes.

    Company MediumPremium
  16. #316
    Implement a prefix trie: Missing prefix

    Return False when no inserted word begins with the requested prefix.

    Company MediumPremium
  17. #317
    Find dictionary words in a board: Several board words

    Find all dictionary words that can be formed by adjacent cells without reuse.

    Company HardPremium
  18. #318
    Find dictionary words in a board: No word can be formed

    Report None when every dictionary word is impossible on the board.

    Company HardPremium
  19. #319
    Find maximum binary-tree path sum: Best path crosses a subtree root

    Find the greatest sum along any connected path in the tree.

    Company HardPremium
  20. #320
    Find maximum binary-tree path sum: All negative values

    Choose the least negative single node when every extension would reduce the sum.

    Company HardPremium