Issue with code : PYTHON

What’s issue with this code.
i tried the same question on leetcode because of input-output issues

Question Link

"""
# Definition for a Node.
class Node:
    def __init__(self, val, prev, next, child):
        self.val = val
        self.prev = prev
        self.next = next
        self.child = child
"""

class Solution:
    def flatten(self, head: 'Node') -> 'Node':
        if head is None:
            return None
        d_head=Node(0,None,head,None)
        prev_p=d_head
        curr=None
        stack=[]
        stack.append(head)
        while len(stack)!=0:
            curr=stack.pop()
            prev_p.next=curr
            curr.prev=prev_p
            if curr.next:
                stack.append(curr.next)
            if curr.child:
                stack.append(curr.child)
                curr.child=None
        prev_p=curr
        d_head.next.prev=None
        return d_head.next

code is correct
only one mistake
`

prev_p=curr` this should come inside loop
Modified Code

Yups!
resolved
Thank you

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

plz give your valuable feed back

how to make submission of same question on leetcode
also please check your inbox @asaurabh_26