Your Dashboard
Interview Coaching
Learn
System Design
ML System Design
Code
Behavioral
Salary Negotiation
Interview Guides
Search
⌘K
Get Premium
Leetcode 2509. Cycle Length Queries in a Tree
Given a complete binary tree labeled 1..2^n-1, each query adds an edge between nodes a and b and asks for the length of the unique cycle created. The task reduces to computing the tree distance between a and b (via their LCA in the implicit heap-like tree where parent = floor(val/2)), then returning distance+1 for each query.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
All Regions
Comments
Hello Interview Premium
Your account is free and you can post anonymously if you choose.