FastPrepSort Trades

Sort Trades

Jane Street logoJane Street● EasyNEW GRADFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated

Problem statement

A trading system keeps a list of the trades it has done today. Each trade is written as trades[i] = [tradeId, price, time], where tradeId is a unique number for the trade, price is the price it traded at and time is when it happened.

The system needs a feature that shows the trades in sorted order. Sort them by these rules:

  • A trade with a lower price comes first.
  • If two trades have the same price, the one with the earlier time comes first.
  • If they also have the same time, the one with the smaller tradeId comes first.

Return the trade ids in sorted order.

Try to write the sorting step yourself instead of calling a library sort.

Function

sortTrades(trades: int[][]) → int[]

Examples

Example 1

trades = [[7,101,30],[3,99,45],[5,101,12],[9,100,30]]return = [3,9,5,7]

The lowest price is 99, so trade 3 comes first. Next is price 100, trade 9. Trades 7 and 5 both have price 101; trade 5 happened earlier (time 12 before 30), so it goes first.

Example 2

trades = [[4,250,10],[2,250,10],[8,250,5]]return = [8,2,4]

All three trades have the same price. Trade 8 has the earliest time 5, so it comes first. Trades 4 and 2 share both price and time, so the smaller id 2 goes before 4.

Example 3

trades = [[1,500,0]]return = [1]

There is only one trade, so the answer is just its id.

Constraints

  • 1 <= trades.length <= 2000
  • trades[i].length == 3
  • 1 <= tradeId, price <= 106
  • 0 <= time <= 109
  • All tradeId values are different.

More Jane Street Phone Screen questions

Similar questions at other companies

Interview reports that mention this question

Jane Street interview experiences

All Jane Street interview questionsSee Jane Street hiring insights
Saved
class Solution {
    public int[] sortTrades(int[][] trades) {
      // Write your code here.
    }
}
Checking account…