Please check code for Tree Top view problem

hello @sahilkhan2312000131

the code that u shared is of top view or bottom view? pls check and confirm

It is of top view just the function name is bottom view

ss

here hd is an integer and ur set is of type pair<int,int>.

so while using find function u need to pass pair instead of integer becuase in set u r storing pairs and not integer

note : map and set are not same thing. in map we have key value pair (i,e a key is mapped to some value) whereas in set we store only values (in thsi case we are storing pair<int,int> )

so what should i do if I want to check if the set contains pair(hd,anyvalue) or not??

…

we can do this using set, but it will just introduce unecessary complexities. so its not recommended

find lower bound of {hd,INT_MIN} (it will return iterator) in set, and then check the first value of the returned iterator,if it is eqwual to hd then present otherwise not.

…
map is the best datastructure in such scenarios.

Coding Blocks IDE
Getting wrong output

check now->

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.