BackhardTrie

Minimal Layer Depth Solution

Problem Statement

Given a trie data structure, design an algorithm to find the minimum depth of the trie. The minimum depth is defined as the minimum number of layers from the root to a leaf node. A leaf node is a node with no children.

Example 1
Input
Insert 5, 3, 7, 2, 8 in order and find the minimum depth
Output
1

Explanation: Since a node with no children is a leaf node, and all nodes except 5 have no children in the order they were inserted, the minimum depth is 1.

Example 2
Input
Insert 10, 9, 1 and find the minimum depth
Output
1

Explanation: Since a node with no children is a leaf node, the minimum depth is 1.

Constraints

  • The input will contain at least one node and at most 10^5 nodes
  • Each node value is unique and ranges from 1 to 10^6
  • The input guarantees at least one leaf node
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free