Amazon 2025-November | CP | Lowest Common Ancestor (Binary Lifting)
Microsoft · Question · Posted Jun 2026
Question 1: Lowest Common Ancestor Problem Statement You are given a Tree consisting of N nodes (rooted at node 1). You will be given Q queries. Each query consists of two nodes U and V. For each query, you must find the Lowest Common Ancestor (LCA) of nodes U and V. Input Format The first line contains a single integer N - the number of nodes. The next N-1 lines contain two space-separated integers u and v denoting an undirected ...
The full answer & interview discussion are available to premium members.
Log in Create a free account