← Questions

Is a sequence a subsequence of a tree's in-order traversal?

0
AirbnbCodingLast asked Sep 2025

Given a binary tree and a sequence of numbers, decide whether the sequence appears, in order, within the tree's in-order traversal (not necessarily next to each other). Walk the tree in order and advance a pointer in the sequence on each match. Then do it with no extra space, using Morris traversal. Follow-up: when it is not a subsequence, change the tree as little as possible so that it is.

Write and test your solution herePython in your browser, the question's tests level by level, saved for you.Sign in to start coding