Solve stock, BFS path, and merge intervals
Company: Amazon
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Technical Screen
Quick Answer: This question evaluates algorithmic problem solving across array scanning, BFS-based constrained shortest-path selection, and interval merging, with emphasis on time/space complexity reasoning, correctness proofs, and thorough edge-case handling. It is commonly asked to assess efficiency guarantees (e.g.
Best Stock Trade with One Transaction
Examples
Input: ([7, 1, 5, 3, 6, 4],)
Expected Output: [5, 1, 4]
Explanation: Buy day 1 sell day 4.
Input: ([7, 6, 4],)
Expected Output: [0, -1, -1]
Explanation: No profit.
Input: ([1, 2, 2],)
Expected Output: [1, 0, 1]
Explanation: Earliest buy on tie.
Lexicographically Smallest Shortest Path Avoiding Forbidden Nodes
Examples
Input: (5, [(1, 2), (1, 3), (2, 5), (3, 5)], 1, 5, [])
Expected Output: [1, 2, 5]
Explanation: Tie chooses path through 2.
Input: (4, [(1, 2), (2, 4), (1, 3), (3, 4)], 1, 4, [2])
Expected Output: [1, 3, 4]
Explanation: Avoid forbidden.
Input: (3, [(1, 2)], 1, 3, [])
Expected Output: []
Explanation: Unreachable.
Merge Touching Half-Open Intervals
Examples
Input: ([[1, 3], [3, 5], [8, 9]],)
Expected Output: [[1, 5], [8, 9]]
Explanation: Touching intervals merge.
Input: ([],)
Expected Output: []
Explanation: Empty input.
Input: ([[-5, -1], [-2, 2], [3, 3]],)
Expected Output: [[-5, 2], [3, 3]]
Explanation: Negatives and zero-length interval.