How would you like to learn today?
Visualize algorithms in real time, explore them step by step, or challenge yourself with a test.Choose a path to focus—or scroll down to preview all options.
Visualize the algorithm step-by-step with interactive animations in real time.
Read the full explanation, examples, and starter code at your own pace.
Drag and arrange the algorithm steps in the correct execution order.
🧠 Select Active to activate
Follow every state change, comparison, and transformation as the execution unfolds in real time.
📖 Select Passive to activate
You are given a string representing the preorder depth-first search (DFS) traversal of a binary tree. In this traversal, each node is output as a series of dashes followed by its integer value. The number of dashes indicates the node's depth in the tree:
Your task is to reconstruct the original binary tree from this traversal string and return the tree's root.
Implement a function that, given the preorder traversal string, recovers the binary tree and returns its root.
Input:
traversal = "10-20--30--40-50--60--70"
Output:
[10, 20, 50, 30, 40, 60, 70]
Explanation:
Input:
traversal = "8-9--10---11-12--13---14"
[8, 9, 12, 10, null, 13, null, 11, null, 14]
Explanation:
Input:
traversal = "100-200--300---400---500-600--700"
Output:
[100, 200, 600, 300, null, 700, null, 400, 500]
Explanation:
🎯 Select Challenge to activate
Drag and arrange the algorithm steps in the correct execution order instead of spending time typing code letter by letter.
The algorithm is divided into three logical parts. Carefully rearrange each section in the correct order to form a complete and valid solution.
Understand Below AlgorithmGreen text means the instruction is placed in the correct position.
Red text means the instruction is in the wrong position.
Instructions with the same background color indicate particular blocks start and end.
A tick mark means the instruction is correct and locked.
🔒 Locked steps cannot be moved. Only unlocked steps are draggable.
🔊 Enable sound for swap feedback and completion effects.