Can you do it with DSU? I am stuck at 42/44. Failed Test Case: n = 3 [1, -1, -1] [-1, -1, 1] I am checking for connected components == 1 plus no cycles. What am I missing??
Length of all unique nodes is 1 which is not equal to n-1. Should do this check right after making a list of unique nodes. And if fails return false even before doing anything else
Was waiting for this solution today
Same can be done with stack to reduce memory
Was waiting for this from 6 hours haha
Thank you brother
Thank you for this video
Can you do it with DSU? I am stuck at 42/44.
Failed Test Case:
n = 3
[1, -1, -1]
[-1, -1, 1]
I am checking for connected components == 1 plus no cycles. What am I missing??
there are 2 root nodes, which is not a valid binary tree (has only 1 root node)
Length of all unique nodes is 1 which is not equal to n-1. Should do this check right after making a list of unique nodes. And if fails return false even before doing anything else
got it just made a ChildToPar hasmap for checking that
@@akhilchauhan9417 use set instead
how we can improve the space?
Thankyou❤
Love