PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Amazon

Solve tree and DP problems

Last updated: Apr 12, 2026

Quick Overview

This pair of problems evaluates proficiency with tree data structures and traversal concepts (deepest shared ancestor) and with dynamic programming/state optimization on linear arrays (maximizing non-adjacent house values), assessing algorithmic reasoning, complexity awareness, and data-structure manipulation.

  • medium
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Solve tree and DP problems

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

This coding round contained two algorithm questions: 1. **Deepest shared ancestor in a binary tree** You are given the root of a binary tree and two distinct nodes `p` and `q` that both exist in the tree. Return the deepest node that is an ancestor of both `p` and `q`. A node may be considered an ancestor of itself. 2. **Maximize money from non-adjacent houses** You are given an integer array `money` where `money[i]` is the amount of money stored in the `i`th house on a street. You may not take money from two adjacent houses on the same night. Return the maximum total amount you can collect.

Quick Answer: This pair of problems evaluates proficiency with tree data structures and traversal concepts (deepest shared ancestor) and with dynamic programming/state optimization on linear arrays (maximizing non-adjacent house values), assessing algorithmic reasoning, complexity awareness, and data-structure manipulation.

Related Interview Questions

  • Find Two-Word Compound Words - Amazon (hard)
  • Minimum Path Length Through a Grid With One Allowed Cell Conversion - Amazon (medium)
  • Circular Drone Hub Delivery Route - Amazon (hard)
  • Leaf Domain Cumulative Scores - Amazon (medium)
  • Kth Largest Perfect Binary Subtree - Amazon (medium)
|Home/Coding & Algorithms/Amazon

Solve tree and DP problems

Amazon logo
Amazon
Oct 24, 2025, 12:00 AM
mediumSoftware EngineerTechnical ScreenCoding & Algorithms
18
0

This coding round contained two algorithm questions:

  1. Deepest shared ancestor in a binary tree
    You are given the root of a binary tree and two distinct nodes p and q that both exist in the tree. Return the deepest node that is an ancestor of both p and q . A node may be considered an ancestor of itself.
  2. Maximize money from non-adjacent houses
    You are given an integer array money where money[i] is the amount of money stored in the i th house on a street. You may not take money from two adjacent houses on the same night. Return the maximum total amount you can collect.

Submit Your Answer to Earn 20XP

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
  • AI Coding 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.