Sort Trades
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
pricecomes first. - If two trades have the same
price, the one with the earliertimecomes first. - If they also have the same
time, the one with the smallertradeIdcomes 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 <= 2000trades[i].length == 31 <= tradeId, price <= 1060 <= time <= 109- All
tradeIdvalues are different.
More Jane Street Phone Screen questions
- Maximum-Scoring Consecutive Tree LevelsPHONE SCREEN · Seen Nov 2026
- Tree Selection and VisibilityPHONE SCREEN · Seen Nov 2026
- Load/Store Arithmetic InterpreterPHONE SCREEN · Seen Oct 2026
- Instrument Stack Language JumpsPHONE SCREEN · Seen Oct 2026
- Run a Stack Language InterpreterPHONE SCREEN · Seen Oct 2026
- Positive-Integer Expression EvaluationPHONE SCREEN · Seen Oct 2026
- Add Two Integers Given as StringsPHONE SCREEN · Seen Sep 2026
- Angle Between Clock HandsPHONE SCREEN · Seen Jul 2026
- Route Length From Two CyclistsPHONE SCREEN · Seen Jul 2026
- Painted Cube: Count and RollPHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- Majority ElementByteDance · PHONE SCREENByteDance interview questions
- Group Transactions by HourAffirm · ONSITE INTERVIEWAffirm interview questions
- Recommend Films from Viewers Who Watched Everything You DidBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Total Years of Work ExperienceLinkedIn · PHONE SCREENLinkedIn interview questions
- Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Employee Count Median, Mean and ModeClay · PHONE SCREEN
- Merge Sorted ArrayDP World · ONSITE INTERVIEW
- Squares of a Sorted ArrayInstacart · PHONE SCREENInstacart interview questions
- Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
- Assign CookiesAmazon · PHONE SCREEN
Interview reports that mention this question
- Jane Street TDOE US Final Round: 11 Experiences (Part 5 of 10)
- Jane Street TDOE UK Coding Round: 15 Experiences (Part 3 of 10)
- Jane Street TDOE UK Final Round: 14 Experiences (Part 2 of 10)
- Jane Street TDOE Interviews: 165 Experiences (Part 1 of 10)
- Jane Street TDOE New Grad Interview Questions: 11 Experiences