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.
Wow! Thats what I wanted to learn. I did the same thing with all the basic concepts, because I got tired with so much work in this problem. But your elegant code took it to next level
static void swapSPL(int k){
int btLevels=maxDepth(root);
//System.out.print("K="+k+", NumberOfLevels="+btLevels);
int j=1;
for(int i=k;i
{
if (node == null)
return;
if (k == 1)
{
//System.out.print(" Swaping for this "+node.key + " ");
Node temp=node.right;
node.right= node.left;
node.left=temp;
return;
}
else
{
swapKDistant(node.left, k - 1);
swapKDistant(node.right, k - 1);
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Swap Nodes [Algo]
You are viewing a single comment's thread. Return to all comments →
Wow! Thats what I wanted to learn. I did the same thing with all the basic concepts, because I got tired with so much work in this problem. But your elegant code took it to next level
static void swapSPL(int k){ int btLevels=maxDepth(root); //System.out.print("K="+k+", NumberOfLevels="+btLevels); int j=1; for(int i=k;i { if (node == null) return; if (k == 1)
{ //System.out.print(" Swaping for this "+node.key + " "); Node temp=node.right; node.right= node.left; node.left=temp; return; }
else { swapKDistant(node.left, k - 1); swapKDistant(node.right, k - 1); } }