Stock Buy Sell Position Indicator
Updated
Problem statement
You are given integer prices and two non-empty movement patterns, buyIndicator and sellIndicator. Each pattern value is 1 for an increase or -1 for a decrease.
Scan prices from left to right and keep the history of non-zero price movements. Equal adjacent prices add no movement and cannot trigger a signal, but they do not erase the earlier non-zero movement history. At each non-equal price, compare the end of that history with both indicators.
A buy match changes the position by +1; a sell match changes it by -1. Both may match at the same index, in which case their changes cancel. Return the cumulative position at every price index, starting with 0 at index 0.
Function
buySellStock(prices: int[], buyIndicator: int[], sellIndicator: int[]) → int[]Examples
Example 1
prices = [51, 56, 56, 58, 60, 59, 54, 57, 52, 48]buyIndicator = [1, 1]sellIndicator = [-1, -1, 1]return = [0, 0, 0, 1, 2, 2, 2, 1, 1, 1]Ignore the unchanged step from 56 to 56 when building the non-zero movement history. The rises ending at indices 3 and 4 each complete [1,1], and the movement ending at index 7 completes [-1,-1,1]. The cumulative positions are therefore [0,0,0,1,2,2,2,1,1,1].
Constraints
prices.length >= 1buyIndicator.length >= 1sellIndicator.length >= 1- Every indicator value is either
1or-1.
More Hudson River Trading interview questions
- Format a Signed Integer with CommasPHONE SCREEN · Seen Nov 2026
- Order and Batch Open-Close LifecyclePHONE SCREEN · Seen Nov 2026
- Count Palindrome Addition ChoicesOA · Seen Nov 2026
- Tilting Maze BallPHONE SCREEN · Seen Oct 2026
- Count Multiples of Three with Two SevensOA · Seen Oct 2026
- Recursively Expanded Shell Command CountsOA · Seen Oct 2026
- Rotate Matrix Regions Around the DiagonalsOA · Seen Oct 2026
- Maximum Diamond SumOA · Seen Oct 2026
- Smallest Most-Lit Street PositionOA · Seen Oct 2026
- Rearrange String by Alternating EndsOA · Seen Sep 2026
Similar questions at other companies
- Payment Partner RoutingStripe · OAStripe interview questions
- Bank Accounts with Balance HistoryMeta · OAMeta interview questions
- Capping Portfolio WeightsCapstone Investment Advisors · OA
- Repeated Mirror XORMathWorks · OAMathWorks interview questions
- Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
- Stabilize Student Test ScoresVirtu Financial · OAVirtu Financial interview questions
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Minimize Task Resource ConsumptionNVIDIA · OANVIDIA interview questions
- Index of the Maximum After Left RotationsChubb · OAChubb interview questions
- Leaves Remaining After WindCresta · OACresta interview questions