Market Data Signal Watcher
Learn this problemProblem statement
Simulate a market-data signal watcher over an ordered batch of updates. Update i sets the latest price of symbols[i] to prices[i].
The configured condition is true exactly when the watcher has received at least one price for watchSymbol and its latest price is greater than or equal to threshold. Before the first price for watchSymbol, the condition is false.
After applying each update, invoke the signal handler exactly when the condition changed from false immediately before that update to true immediately after it. While the condition remains true, later updates do not invoke the handler again. A later update for watchSymbol below threshold makes the condition false and rearms the watcher, allowing a future qualifying update to invoke the handler again. Updates for other symbols preserve the current condition.
Return a boolean array signals, where signals[i] is true if and only if the signal handler is invoked after update i.
Function
marketDataSignals(symbols: String[], prices: int[], watchSymbol: String, threshold: int) → boolean[]Examples
Example 1
symbols = ["AAPL","AAPL","AAPL","AAPL"]prices = [99,100,101,98]watchSymbol = "AAPL"threshold = 100return = [false,true,false,false]The first update leaves the condition false. The price 100 changes it to true and invokes the handler. Price 101 keeps it true without another invocation, and price 98 rearms the watcher without signaling.
Example 2
symbols = ["MSFT","AAPL","MSFT","AAPL","AAPL"]prices = [500,90,510,110,105]watchSymbol = "AAPL"threshold = 100return = [false,false,false,true,false]The MSFT updates do not change the watched condition. The first AAPL price is below the threshold; the later price 110 creates the only false-to-true transition.
Example 3
symbols = ["TSLA","NVDA","TSLA","TSLA","NVDA","NVDA"]prices = [5,10,7,8,9,10]watchSymbol = "NVDA"threshold = 10return = [false,true,false,false,false,true]The first NVDA update reaches the inclusive threshold and signals. Two unrelated updates preserve the true condition. Price 9 rearms the watcher, so the final price 10 signals again.
Constraints
1 <= symbols.length == prices.length <= 2000001 <= symbols[i].length, watchSymbol.length <= 20- Every symbol contains only uppercase English letters, decimal digits, or
_. 0 <= prices[i], threshold <= 10^9
More Hudson River Trading problems
- Count 2x2 Submatrices by Black CellsOA · Seen Jul 2026
- Cumulative Unique BytesOA · Seen Jul 2026
- Backtick Identifier ConverterOA · Seen Jun 2026
- Integer to String Without Built-insPHONE SCREEN · Seen May 2026
- Future Stock PricesOA · Seen Sep 2024
- Count Fancy NumbersOA · Seen Sep 2024
- Increasing Paths, part 2OA · Seen Aug 2024
- Increasing Paths, part 1OA · Seen Aug 2024