We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Here's my solution in C#, which passed all 11 test cases. For each node, you need to keep track of its index, children, and depth, the last one being important for the swap operation since you need to swap every node whose depth is a multiple of the number specified by each query.
Since the swaps affect nodes individually, you can perform the in-order traversal and the child swaps using the same recursion function.
Swap Nodes [Algo]
You are viewing a single comment's thread. Return to all comments →
Here's my solution in C#, which passed all 11 test cases. For each node, you need to keep track of its index, children, and depth, the last one being important for the swap operation since you need to swap every node whose depth is a multiple of the number specified by each query.
Since the swaps affect nodes individually, you can perform the in-order traversal and the child swaps using the same recursion function.