PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Amazon

Implement array and tree traversal tasks

Last updated: Mar 29, 2026

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.

Related Interview Questions

  • Implement Datacenter Router Commands - Amazon (hard)
  • Implement Event Filtering and Queue Routing - Amazon (medium)
  • Determine if all courses can be completed - Amazon (medium)
  • Replace Delimited Tokens in a String - Amazon (medium)
  • Minimize Circular Redistribution Cost - Amazon (medium)
Amazon logo
Amazon
Jan 22, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
5
0
Loading...

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?

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,000+ 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.