As reported: Twilio peer coding round (2025): based on LeetCode Stock Price Fluctuation, implement a REST API around it with CRUD. Each data point has a
stockCode, atimestampand aprice.POSTstores a data point for a stock and timestamp;PUTupdates its price;DELETEdeletes the price point;GETreturns the latest, minimum and maximum price of the stock. A timestamp is unique within a stock.
Build the service layer behind this API:
| Endpoint | Method |
|---|---|
POST /stocks/{stockCode}/prices {timestamp, price} |
post(stockCode, timestamp, price) |
PUT /stocks/{stockCode}/prices/{timestamp} {price} |
put(stockCode, timestamp, price) |
DELETE /stocks/{stockCode}/prices/{timestamp} |
delete(stockCode, timestamp) |
GET /stocks/{stockCode} |
get(stockCode) |
Implement a StockService class:
post(stockCode, timestamp, price)— store a new data point; returntrue, orfalseif the stock already has a point at this timestamp (a409 Conflict).put(stockCode, timestamp, price)— replace the price of an existing point; returnfalseif there is none (404).delete(stockCode, timestamp)— remove the point; returnfalseif there is none (404).get(stockCode)— return[latest, minimum, maximum], where latest is the price at the stock's largest timestamp; return[]if the stock has no data points (404).
This builds on LeetCode 2034 — Stock Price Fluctuation, adding deletes and per-stock data.
Example
post("TWLO", 1, 60) -> true
post("TWLO", 3, 75) -> true
post("TWLO", 3, 80) -> false timestamp 3 already exists
get("TWLO") -> [75, 60, 75]
put("TWLO", 1, 90) -> true
get("TWLO") -> [75, 75, 90]
delete("TWLO", 3) -> true
get("TWLO") -> [90, 90, 90]
delete("TWLO", 3) -> false
get("AAPL") -> []
Constraints: up to 3·10^4 operations; stockCode is 1–5 uppercase letters; 1 ≤ timestamp ≤ 10^9; 1 ≤ price ≤ 10^5.
Code runner format: two JSON values, one per line (LeetCode's design format): the operation names starting with "StockService", then their argument lists. The harness prints a JSON list of results (null for the constructor).