can there be a better time complexity than O(k*n) for UNION ON TREE?

My sol is of O(k*n)… its showing tle

There has to be one. I can keep giving u k=500000 for n=50000. It is bound to get tle. These number of queries cant even be finished in 10 seconds, leave apart 2.5.

1 Like