PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Amazon

Design LCA with flexible inputs and rule

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's understanding of tree algorithms and lowest common ancestor concepts, including handling both child-list (root-provided) and parent-pointer input models as well as special ancestor-as-manager rules and edge-case handling.

  • Medium
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Design LCA with flexible inputs and rule

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Design a function to find the lowest common manager of two employees in an organizational tree. Support two input models: (A) nodes store a list of children and you are given the root plus nodes a and b; (B) nodes store a parent pointer and you are given only nodes a and b. Provide both a top-down solution from the root and a bottom-up solution using parent pointers. Additional rule: if one node is an ancestor of the other (e.g., b is a descendant of a), return the ancestor’s manager (the parent of that ancestor) rather than the ancestor itself. Specify data structures, algorithms, time/space complexity, and how to handle cases like missing nodes, nodes from different trees, or an undefined manager for the root.

Quick Answer: This question evaluates a candidate's understanding of tree algorithms and lowest common ancestor concepts, including handling both child-list (root-provided) and parent-pointer input models as well as special ancestor-as-manager rules and edge-case handling.

Related Interview Questions

  • Implement Datacenter Router Commands - Amazon (hard)
  • Replace Delimited Tokens in a String - Amazon (medium)
  • Minimize Circular Redistribution Cost - Amazon (medium)
  • Find the Most Common Visit Pattern - Amazon (hard)
  • Maximize Value Under a Budget - Amazon (medium)
Amazon logo
Amazon
Aug 7, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
3
0

Design a function to find the lowest common manager of two employees in an organizational tree. Support two input models: (A) nodes store a list of children and you are given the root plus nodes a and b; (B) nodes store a parent pointer and you are given only nodes a and b. Provide both a top-down solution from the root and a bottom-up solution using parent pointers. Additional rule: if one node is an ancestor of the other (e.g., b is a descendant of a), return the ancestor’s manager (the parent of that ancestor) rather than the ancestor itself. Specify data structures, algorithms, time/space complexity, and how to handle cases like missing nodes, nodes from different trees, or an undefined manager for the root.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Amazon•More Software Engineer•Amazon Software Engineer•Amazon Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.