PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates algorithmic problem-solving and data-structure competency, specifically array-based optimization for single-trade profit and tree traversal techniques for right-side view, along with time/space complexity analysis and system-level considerations; the domain is Coding & Algorithms.

  • hard
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Implement array and tree traversal tasks

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

You are interviewing for a storage/infra-leaning role. Solve the following coding tasks and be ready to discuss time/space complexity and edge cases. ## Task A: Max profit from one trade Given an integer array `prices` where `prices[i]` is the price of a stock on day `i`, compute the maximum profit achievable by choosing **at most one** buy day `b` and one sell day `s` with `b < s`. If no profit is possible, return `0`. - **Input:** `prices: int[]` - **Output:** `max_profit: int` - **Constraints (typical):** `1 <= n <= 2e5`, prices fit in 32-bit int **Follow-ups:** - What is the best achievable time and space complexity? - How do you handle monotonically decreasing prices? ## Task B: Right-side view of a binary tree Given the root of a binary tree, return the list of node values visible when the tree is viewed from the right side (from top level to bottom level). - **Input:** `root` (binary tree node) - **Output:** `right_view: int[]` **Follow-ups:** - Compare DFS vs BFS approaches and their complexities. - What are edge cases (empty tree, skewed tree, very deep tree)? ## Discussion (no coding required, but explain clearly) - If the code were used in a **multi-threaded** environment or under **very large datasets**, what assumptions break and what changes (if any) would you make?

Quick Answer: This question evaluates algorithmic problem-solving and data-structure competency, specifically array-based optimization for single-trade profit and tree traversal techniques for right-side view, along with time/space complexity analysis and system-level considerations; the domain is Coding & Algorithms.

Max Profit from One Stock Trade

Return the maximum profit from at most one buy before one sell.

Constraints

  • Inputs are provided as Python literals matching the function signature.
  • Return a deterministic exact-match result.

Examples

Input: ([7,1,5,3,6,4],)

Expected Output: 5

Explanation: Buy at 1 sell at 6.

Input: ([7,6,4,3,1],)

Expected Output: 0

Explanation: No profit.

Input: ([5],)

Expected Output: 0

Explanation: Single price.

Hints

  1. Choose a representation that makes the core operation simple.
  2. Handle empty and boundary inputs before the main algorithm.

Right Side View of a Binary Tree

Given a binary tree as level-order values with None holes, return the visible node values from the right side.

Constraints

  • Inputs are provided as Python literals matching the function signature.
  • Return a deterministic exact-match result.

Examples

Input: ([1,2,3,None,5,None,4],)

Expected Output: [1, 3, 4]

Explanation: Classic right view.

Input: ([],)

Expected Output: []

Explanation: Empty tree.

Input: ([1,None,2,None,None,3],)

Expected Output: [1, 2, 3]

Explanation: Right skew represented in level order.

Hints

  1. Choose a representation that makes the core operation simple.
  2. Handle empty and boundary inputs before the main algorithm.
Last updated: Jun 27, 2026

Loading coding console...

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.

Related Coding Questions

  • 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)
  • Find Conflicting Events - Amazon (medium)