I tried to solve this problem using HLD and Segment Tree. I didn't find LCA explicitly rather used HLD.
Code: https://pastebin.ubuntu.com/p/BfxMZH9hz3/
This solution gives runtime error. I can't find any reason for this kind of verdict.
I have already read this blog but couldn't understand why my code isn't working.
Can anyone help me?