← Microsoft questions

Longest alternating path in a tree

Filed under Microsoft

Given a tree of N nodes rooted at 0 where each node is labeled 'A' or 'B', find the length of the longest path in the tree such that no two adjacent nodes on the path have the same label.

You've read your 3 free write-ups

Sign up free to keep reading. Your account opens the first 10 questions of every company.

Related Microsoft questions

Collected from public candidate posts and coding forums. Updated Nov 2026.