Problem 1372 · Medium

Longest ZigZag Path in a Binary Tree

Track two runs per node, one starting left and one starting right, and combine each with the opposite run of its child.

Open the interactive visualisation