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.
No need to build a tree. Just swap the numbers in the list.
sys.setrecursionlimit(2000)defswapNodes(indexes,queries):# Write your code hereresult=[]indexes=[[]]+indexesforkinqueries:res=[]swap(indexes,0,1,k,res)result.append(res)returnresultdefswap(nodes,depth,curr,k,result):ifcurr==-1:returnifdepth%k==k-1:nodes[curr][0],nodes[curr][1]=nodes[curr][1],nodes[curr][0]swap(nodes,depth+1,nodes[curr][0],k,result)result.append(curr)swap(nodes,depth+1,nodes[curr][1],k,result)
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 →
No need to build a tree. Just swap the numbers in the list.