This question evaluates algorithmic problem-solving skills related to array processing, optimization under constraints, and reasoning about performance trade-offs by presenting a maximum single-transaction stock profit problem and a minimum banana-eating speed problem.
Solve both coding problems below.
prices
where
prices[i]
is the stock price on day
i
, return the maximum profit obtainable by choosing one day to buy and a later day to sell. If no profit is possible, return
0
.
piles
where
piles[i]
is the number of bananas in pile
i
, and an integer
h
representing the total number of hours available, find the minimum integer eating speed
k
such that a monkey can finish all piles within
h
hours. In one hour, the monkey chooses one pile and eats up to
k
bananas from that pile.
For each problem, explain your algorithm and analyze time and space complexity.