@@ -0,0 +1,2372 @@
+//https://www.hackerrank.com/challenges/swap-nodes-algo%0Aimport java.io.*;%0A%0Apublic class Solution %7B%0A    %0A    public static void main(String%5B%5D args) throws IOException %7B%0A        %0A        //I/O%0A        final StringBuilder sb = new StringBuilder();%0A        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));%0A        %0A        //Get number of nodes%0A        final short N = Short.parseShort(br.readLine());%0A        %0A        //Create nodes%0A        final Node%5B%5D nodes = new Node%5BN%5D;%0A        for(int i = 0; i %3C N; ++i)%7B%0A            nodes%5Bi%5D = new Node(i+1);%0A        %7D%0A        %0A        //Get children per node%0A        for(short i = 0; i %3C N; ++i)%7B%0A            final String%5B%5D line = br.readLine().split(%22 %22);%0A            final short A = (short)(Short.parseShort(line%5B0%5D) - 1);%0A            final short B = (short)(Short.parseShort(line%5B1%5D) - 1);%0A            nodes%5Bi%5D.left = (A %3C 0) ? null : nodes%5BA%5D;%0A            nodes%5Bi%5D.right = (B %3C 0) ? null : nodes%5BB%5D;%0A        %7D;%0A        %0A        //For each swap operation...%0A        for(byte T = Byte.parseByte(br.readLine()); T %3E 0; --T)%7B%0A            %0A            //Get swap interval%0A            final short K = Short.parseShort(br.readLine());%0A            swap(nodes%5B0%5D, K);%0A            %0A            //Print output%0A            printInorder(nodes%5B0%5D, sb);%0A            sb.append(%22%5Cn%22);%0A        %7D%0A        System.out.print(sb);%0A    %7D%0A    %0A    private static void swap(final Node node, final short K)%7B%0A        swap(node, K, (short)1);%0A    %7D%0A    %0A    private static void swap(final Node node, final short K, short depth)%7B%0A        if(node == null)%7B%0A            return;%0A        %7D%0A        if(depth == K)%7B%0A            depth = 0;%0A            Node t = node.left;%0A            node.left = node.right;%0A            node.right = t;%0A        %7D%0A        swap(node.left, K, ++depth);%0A        swap(node.right, K, depth);%0A    %7D%0A    %0A    private static void printInorder(final Node node, final StringBuilder sb)%7B%0A        if(node != null)%7B%0A            printInorder(node.left, sb);%0A            sb.append(node.val + %22 %22);%0A            printInorder(node.right, sb);%0A        %7D%0A    %7D%0A    %0A    private static class Node %7B%0A        public Node left;%0A        public Node right;%0A        public final int val;%0A        public Node(final int val)%7B%0A            this.val = val;%0A            this.left = null;%0A            this.right = null;%0A        %7D%0A    %7D%0A%7D%0A

Create swap-nodes-algo.java