← All problemsSign in

Weird Paths in a tree

You are given a tree. Each node of the tree is assigned a distinct value. A path in the tree is considered weird if the values in the path increase and decrease alternatively. For example: Consider a straight chain of nodes 1→3→2→4→5 with value assigned to any node i being i itself. Then the path 3→2→4, 1→3→2, etc. are weird whereas 1→3→2→4→5 is not weird because 2→4 and 4→5 are both increasing.

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start