Data Structures & AlgorithmsVery hardProduct Company SDE · Amazon OA
Problem: Stock trading allows unlimited transactions, but after selling you must wait one day before buying (cooldown). Prices are [1, 2, 3, 0, 2]. What is the maximum profit?
- A. 3
- B. 4
- C. 2
- D. 5
Correct answer: A. 3
Track three states per day: holding a stock, just sold (cooldown next day), and resting. The cooldown rule forbids buying on the day after a sale, which the state machine enforces.
More Coding Interview Problems questions
- Problem: Josephus with step 3: 10 people numbered 1 to 10 stand in a circle. Starting from person 1, count 3 people and eliminate the…
- Problem: The sequence x0 = 1 and x(n+1) = (3·x(n) + 1) mod 7 is generated. The first repeated value appears at some step. What is the…
- Problem: A ball starts at position 0 on a track from 0 to 10 and moves 3 units per second. At each boundary it reverses direction…
- Problem: The permutation [2, 1, 4, 3] is processed by a single stack: input elements are pushed in order and popped whenever the popped…
- Problem: How many integers from 1 to 500 are coprime to 30 (share no prime factor with 30 = 2·3·5)?
- Problem: What is the sum of all prime numbers less than 30?