โ† PayU questions

Swap subtrees rooted at two nodes

Filed under PayU

The question

Given a binary tree and two pointers p1 and p2 to two nodes, swap the subtrees rooted at these nodes while handling base cases such as ancestry.

No write-up yet. Related questions below have one.

Related PayU questions

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