FastPrepTriggered Order Event Filter

Triggered Order Event Filter

Headlands Technologies logoHeadlands Technologies● EasyFULLTIMEONSITE INTERVIEW
Learn

Problem statement

You receive orders in arrival order. Each row is [price, side], where side == 1 means BUY and side == 0 means SELL. An order is identified by its zero-based position in the input; identical rows remain distinct orders.

Start an inactive filter. Count every order whose price >= threshold, regardless of side. The first order that brings this count to triggerCount activates the filter. That triggering order is excluded from the output.

After activation, return the indices of the next takeCount BUY orders, preserving arrival order. Their prices do not need to meet the threshold, and SELL orders do not use up the requested count. Activation occurs only once; later qualifying orders do not reset or restart the filter.

If activation never occurs, return an empty array. If fewer BUY orders remain, return all that remain. A zero take count also returns an empty array. Implement filterOrdersAfterTrigger; its finite array interface can be backed by an object that consumes one order at a time.

Function

filterOrdersAfterTrigger(orders: int[][], triggerCount: int, threshold: int, takeCount: int) → int[]

Examples

Example 1

orders = [[100,0],[80,1],[110,1],[100,0],[90,0],[130,0],[100,1],[5,0],[2,1],[999,0],[3,1],[200,1]]triggerCount = 5threshold = 100takeCount = 3return = [8,10,11]

The fifth qualifying order is index6, which is excluded even though it is BUY. The next three BUY orders have indices8,10,11.

Example 2

orders = [[11,1],[9,1],[10,0],[1,0],[2,1],[8,1]]triggerCount = 2threshold = 10takeCount = 3return = [4,5]

Both sides count toward activation. Index2 activates the filter; only two subsequent BUY orders exist, at4and5.

Example 3

orders = [[10,1],[0,1],[20,1]]triggerCount = 1threshold = 10takeCount = 0return = []

A zero take count requests no orders, so the result is empty.

Constraints

  • 0 <= orders.length <= 100000.
  • Each row contains exactly two integers with 0 <= price <= 1000000000 and side equal to 0 or 1.
  • 1 <= triggerCount <= 1000000000.
  • 0 <= threshold, takeCount <= 1000000000.
  • All orders are valid and processed in the supplied order. There are no cancellations, amendments, resets or concurrent arrivals.

More Headlands Technologies problems

See Headlands Technologies hiring insights
public int[] filterOrdersAfterTrigger(int[][] orders, int triggerCount, int threshold, int takeCount) {
    // write your code here
}
orders[[100,0],[80,1],[110,1],[100,0],[90,0],[130,0],[100,1],[5,0],[2,1],[999,0],[3,1],[200,1]]
triggerCount5
threshold100
takeCount3
expected[8,10,11]
Checking account…