FastPrepTop Trade Events by Notional

Top Trade Events by Notional

Headlands Technologies logoHeadlands Technologies● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

You are given parallel arrays tickers, prices and volumes describing trade events. Event i has ticker tickers[i], price prices[i] and volume volumes[i]. Its notional is the exact product prices[i] * volumes[i].

For each distinct ticker, retain its event with the greatest notional. Do not sum its events. If several events for the same ticker share the greatest notional, retain the earliest input index.

Return the original indices of the top k retained events, in descending notional order. Break equal-notional ties between tickers by ascending, case-sensitive ASCII ticker order. Each returned index identifies the complete original event, and no ticker may appear twice.

If k exceeds the distinct-ticker count, return every retained event in that order. An empty input or k == 0 returns an empty array. Do not modify the input arrays.

Calculate and compare notionals as exact signed 64-bit integers. In C++, cast an operand to long long before multiplying; casting an already-overflowed int product is too late. Do not use floating-point scores.

Function

getTopTradeEventIndices(tickers: String[], prices: int[], volumes: int[], k: int) → int[]

Examples

Example 1

tickers = ["a","b","a","c","b"]prices = [10,200,100,50,10]volumes = [10,100,100,10,100]k = 2return = [1,2]

Ticker a keeps the event at2 with notional10000, not the sum of its events. Ticker b keeps index1 with notional20000, so the selected original indices are1and2.

Example 2

tickers = ["b","a","a","c"]prices = [2,5,1,0]volumes = [5,2,10,999]k = 4return = [1,0,3]

Ticker a has equal maxima at1and2, so retain earliest1. Both a and b score10; ASCII ticker order places a before b. Only three distinct tickers exist.

Example 3

tickers = ["x","y","x"]prices = [1000000000,999999999,1000000000]volumes = [1000000000,1000000000,999999999]k = 1return = [0]

The event at0 has notional1000000000000000000. Use an exact64-bit product; neither the later x event nor y is larger.

Constraints

  • 0 <= tickers.length == prices.length == volumes.length <= 100000.
  • Each ticker has between 1 and 20 characters, all ASCII uppercase letters, lowercase letters or digits. Tickers are case-sensitive.
  • 0 <= prices[i], volumes[i] <= 1000000000.
  • 0 <= k <= 1000000000.
  • Every notional is at most 10^18 and fits in a signed 64-bit integer.

More Headlands Technologies problems

See Headlands Technologies hiring insights
public int[] getTopTradeEventIndices(String[] tickers, int[] prices, int[] volumes, int k) {
    // write your code here
}
tickers["a","b","a","c","b"]
prices[10,200,100,50,10]
volumes[10,100,100,10,100]
k2
expected[1,2]
Checking account…