 What's up guys my name is Michael and welcome to my YouTube channel today. We're gonna do another leak code challenge It's called uni value to binary tree a binary tree is uni value of every node in the tree has the same value Return true if and only if the given tree is uni value As you can see here, this is binary tree all the values are the same One one one one one, okay, so it's returns true. Oh, yeah, you could also have null So here this values null and they're fine with that. So Yeah As you can see here, there's one five Therefore it returns false because this should be a two they should all have the values of two But there's a five here. That's why it's a false. It's not uni value So I'll give you a few minutes to do this yourself and then I'll go over the solution Art to go over the solution Basically, we need to check that the left tree left side is Univalued uni value uni valued We have to check if the left side is at uni valued and we have to check if the right side is uni valued Okay, that's what I'm gonna tell you guys because they both have to be uni valued the left side and the right side They both have to be uni valued in order for this to work and They both have to be uni valued. So we have to return left side uni valued and right side right side uni valued, okay So I'm just explaining The left side of these has to be uni valued and the right side has to uni valued Okay, so How does the left side have to be uni valued? Well either In order for the left side to be uni valued Let the left tree of the root has to be uni valued. So Is uni value tree? We have to check if the left part of The tree is uni valued and Is the right side uni valued? We have to check is Uni valued tree is the right part uni valued Okay So but it's not just that okay, it's not just that we also have to check is the left side null Okay, and We have to check if the value at the current root is equal to the Roots left and the value at the Current node root is equal to roots right rights value. Okay. That's what we have to do so One thing the thing so we have to check is root Roots value is it equal to roots left? Left value I think that's how it works. Yeah, is equal to roots left value and this And we have to check is roots right roots value equal to roots right value Okay, because otherwise if it's not Then we know it's not a Uni value tree because the roots value the values have to be the same. Okay, so that's what this is doing and then Another condition we have to check is if the roots left is null then It doesn't matter about this condition at all So this whole condition it would not matter because we could have a left value as null So it wouldn't matter. So we got to check roots left Is equal to null and if it is and it wouldn't matter so We have an it or or a statement Okay, then we don't do the this very part. Okay, and We got to check if roots right is null because if it's the right snow then it could also Be right side univalued Okay Let's run the code See if this changes anything mm-hmm mm-hmm It's taking awfully a long time Something's not right Did you something wrong? I'm pretty sure I'm doing it right. Let's just check the solution to make you see if it's I'm doing this correctly. Yeah, left value and yeah Okay, yeah, so I did this right right side rides an equal to null or Right that value is equal to root that value is written value and Right side. Okay. Yeah, so that this should be right. It's just taking a while. I think it's my internet speed is pretty low but Essentially, this is how you do it It's taking awfully a long time That's so strange. Okay I'm gonna refresh the page Yeah, that's basically how you do it. I think my interest internet speeds pretty bad Yeah That was basically the solution. You had to check if the left side is left left as route is roots value is equal to the left side and the Left subtree is a univalued tree Then the left side is univalued or if if the left side is null Then it could also be univalued because it doesn't matter the net left sides and all it doesn't really matter Check if the right sides know if right sides know it doesn't really matter, but what really matters is a You know to check if the rights value is equal to roots value Okay, right subtree of value is equal to roots value because this this part one one has to be the same See the right to try to subtree one has to be the same as this the main tree The main node of one one one, okay, and the right the rest of the right subtree has to be univalued. So That's basically how you do it awesome minute You know a few minutes seconds Time but yeah, that's basically how you do it. Ready come subscribe. I'll check you guys later. Peace