Showing:
Handle Score
@Ibrahim Nash 6420
@mb1973 5704
@Quandray 5245
@akhayrutdinov 5111
@saiujwal13083 5046
@sanjay05 3762
@kirtidee18 3673
@marius_valentin_dragoi 3523
@mantu_singh 3510
@sushant_a 3459
Exchange the Leaf Nodes
Easy Accuracy: 34.69% Submissions: 7780 Points: 2

Given a binary tree of size N, your task is to complete the function pairwiseSwap(), that swap leaf nodes in the given binary tree pairwise starting from from left to right.
Example 1:

Input:

Output: 7 2 1 4 5 9 3 8 6 10

Explanation:
The sequence of leaf nodes in original binary tree
from left to right is (4, 7, 8, 9, 10). Now if we
try to form pairs from this sequence, we will have
two pairs as (4, 7), (8, 9). The last node (10) is
unable to form pair with any node and thus left unswapped

Example 2:

Input:
1
/     \
2       3
\    /    \
5  6      7
Output: 2 6 1 5 3 7
1
/     \
2       3
\    /   \
6  5     7

You don't need to read input or print anything. Your task is to complete the function pairwiseSwap() which takes root node of the tree as input parameter.

Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)

Constraints:
1<=N<=103
1<=Data of a node <=103