Easy Recursive and Iterative solutions
Iterative:\n\n\nvar flatten = function(head) {\n    const stack = [];\n    let ptr = head;\n    \n    while(ptr || stack.length) {\n        if(ptr.child) {\n   
**Iterative**:\n\n```\nvar flatten = function(head) {\n    const stack = [];\n    let ptr = head;\n    \n    while(ptr || stack.length) {\n        if(ptr.child) {\n            if(ptr.next)\n                stack.push(ptr.next);\n            let child = ptr.child;\n            ptr.child = null;\n            ptr.next = child;\n            child.prev = ptr;\n            ptr = child;\n        } else if(ptr.next === null && stack.length) {\n            let next = stack[stack.length - 1];\n            ptr.next = next;\n            next.prev = ptr;\n            stack.pop();\n        } else {\n            ptr = ptr.next;\n        }\n    } \n    \n    return head;\n};\n```\n\n**Recursive:**\n\n```\nvar flatten = function(head) {\n        const dfs = (ptr) => {\n        let last = null;\n        while(ptr) {\n            if(ptr.child) {\n\t\t\t    //go deep and return to previous caller\n                let node = dfs(ptr.child);\n                \n                let next = ptr.next;\n                let newHead = ptr.child;\n                ptr.child = null;\n                ptr.next = newHead;\n                newHead.prev = ptr;\n                node.next = next;\n                \n                if(next)\n                    next.prev = node;\n            }\n            last = ptr;\n            ptr = ptr.next;\n        }\n        return last;\n    }\n    \n    dfs(head);\n}\n```
['Recursion', 'Iterator', 'JavaScript']