DSAWiser

DSA question sets + code visualization

From Your
First Problem
to Your Hardest

Start with Basic questions. Build the foundations, learn the patterns, then progress to Easy, Medium, and Hard.

Write your solution and visualize your code step by step.

Try the demos without an account. Sign up to practice with your own code.

Practice questions
3,938
Question sets
26
Languages
8

Supported languagesJavaScript · TypeScript · Python · Java · C++ · C · Go · Rust

countNodes.jsJavaScript · Recursion
function countNodes(node) {
if (!node) return 0;
const left = countNodes(node.left);
const right = countNodes(node.right);
return 1 + left + right;
}
Count a tree, one call at a time Current Returned
An 11-node binary treeRoot 8 has children 4 and 12. Node 4 has children 2 and 6; node 12 has children 10 and 14. Node 2 has children 1 and 3; node 6 has children 5 and 7. Return badges show subtree node counts.84122610141357
Call stack
  1. 8
left
—
right
—
return
—

Visit node 8. Count its left and right subtrees.

Try visualizer yourself

Question sets

Featured sets

7 of 26 question sets shown

Want a worked example? How to trace a Two Sum solution

Try one question in the editor.

Create a free account, write a solution, and inspect it with the visualizer.

Sign up for free