Solution approach suggests that we can use two arrays / arrayLists to store path of two given values. After storing the path we can traverse the array and return least common ancestor.
I had coded using the same approach with O(n) time complexity. But this solution is not accepted.
you can check my previous submissions. My first and second submission has this approach.
But still I got TLE. When I checked my previous submissions it says “Wrong Answer on test 3”.
Can you please check this ? I spent 2 hours more to get the solution with same complexity but with another approach.
@anshumansingh can you please send what the test 3 was .