← AlgoMindset 75

Leaf-Similar Trees

Easy🎙 Interview me on this

🧠 Before you code — what pattern fits?

The leaf value sequence of a binary tree is the values of its leaves read from left to right. Two trees are leaf-similar if their leaf value sequences are the same. Given the roots of two trees, return true if they are leaf-similar.

[3,5,1,6,2,9,8,null,null,7,4] vs [3,5,1,6,7,4,2,null,null,null,null,null,null,9,8] → true

🎬 Video explanation · NeetCodeIO

Your solution runs against 2 unit tests, including edge and large-value cases.

Loading...

Test console · 2 unit tests

Submit your code to run it against all 2 unit tests. Results appear here.

JavaScript, TypeScript & Python run sandboxed in your browser; other languages run on the execution server. Your code is saved locally as you type.