Implement array and tree traversal tasks
Company: Amazon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
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
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
- Choose a representation that makes the core operation simple.
- Handle empty and boundary inputs before the main algorithm.
Right Side View of a Binary Tree
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
- Choose a representation that makes the core operation simple.
- Handle empty and boundary inputs before the main algorithm.