JAVA Recursion Code or DFS 100% faster with Explaination
use of simple dfs firstOrder\n\n\n/*\n// Definition for a Node.\nclass Node {\n    public int val;\n    public Node prev;\n    public Node next;\n    public Nod
use of simple dfs firstOrder\n\n```\n/*\n// Definition for a Node.\nclass Node {\n    public int val;\n    public Node prev;\n    public Node next;\n    public Node child;\n};\n*/\n\nclass Solution {\n    public static Node ans;\n    public static Node help; // used to keep at top of node\n    public static void DFS(Node n) {\n        if(n==null) {\n            return;\n        }\n        if(ans.val==0) { // if call is 1st time\n            ans.val=n.val;\n            help=ans;\n        } else {\n            Node currentNode = new Node();\n            currentNode.val=n.val;\n            help.next=currentNode;\n            currentNode.prev=help;\n            help=currentNode; // put help at top\n        }\n        DFS(n.child); // 1st call child as we have to putchild 1st\n        DFS(n.next);\n    }\n    public Node flatten(Node head) {\n        if(head==null) {  // if Node is Empty return\n            return head;\n        }\n        ans=new Node(); // make new\n        help=new Node(); // make new\n        DFS(head);  // call DFS function\n        return ans;\n    }\n}\n```
[]