Order and Batch Open-Close Lifecycle
Updated
Problem statement
Open and close events are stored separately. Every event has a positive timestamp, an order ID, and a batch ID.
Given the parallel arrays for both event files plus queryType and queryId, return [start, end] for the requested lifecycle:
- For an
ORDERquery,startis that order's open timestamp.endis its close timestamp, or0if it has no close event. - For a
BATCHquery,startis the earliest open timestamp among its orders. If any order in that batch has no close event,endis0; otherwise,endis the latest close timestamp among those orders.
The input is well formed: every order opens exactly once, closes at most once, and keeps the same batch ID in both files.
Function
getLifecycleWindow(openTimestamps: long[], openOrderIds: String[], openBatchIds: String[], closeTimestamps: long[], closeOrderIds: String[], closeBatchIds: String[], queryType: String, queryId: String) → long[]Examples
Example 1
openTimestamps = [10,12,15]openOrderIds = ["o1","o2","o3"]openBatchIds = ["b1","b1","b2"]closeTimestamps = [20,25]closeOrderIds = ["o1","o3"]closeBatchIds = ["b1","b2"]queryType = "BATCH"queryId = "b1"return = [10,0]Batch b1 starts when o1 opens at 10. Order o2 remains open, so the batch end is 0.
Example 2
openTimestamps = [10,12,15]openOrderIds = ["o1","o2","o3"]openBatchIds = ["b1","b1","b2"]closeTimestamps = [20,25]closeOrderIds = ["o1","o3"]closeBatchIds = ["b1","b2"]queryType = "ORDER"queryId = "o1"return = [10,20]Order o1 opens at 10 and closes at 20.
Example 3
openTimestamps = [5,7,9]openOrderIds = ["a","b","c"]openBatchIds = ["x","x","y"]closeTimestamps = [11,20,15]closeOrderIds = ["a","b","c"]closeBatchIds = ["x","x","y"]queryType = "BATCH"queryId = "x"return = [5,20]Batch x starts at the earlier open time 5. Both orders close, and the later close is 20.
Constraints
- The three open arrays have equal positive length; the three close arrays have equal length.
- All timestamps are positive 64-bit integers, and each close timestamp is at least its order's open timestamp.
- Every order ID appears exactly once in the open arrays and at most once in the close arrays.
- A close event uses the same batch ID as its order's open event.
queryTypeisORDERorBATCH, andqueryIdidentifies an existing order or batch of that type.
More Hudson River Trading Phone Screen questions
- Format a Signed Integer with CommasPHONE SCREEN · Seen Nov 2026
- Tilting Maze BallPHONE SCREEN · Seen Oct 2026
- Tiered Expiring Item StorePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Mean vs Median: Chance of Missing the CenterPHONE SCREEN · Seen Sep 2026
- Market Data Signal WatcherPHONE SCREEN · Seen Jul 2026
- Integer to String Without Built-insPHONE SCREEN · Seen May 2026
- Contact Tracing Through Timed MeetingsPHONE SCREEN · Seen Nov 2024
- Polydivisible Pandigital NumbersPHONE SCREEN · Seen Feb 2024
- Defragment a Buffer of ObjectsPHONE SCREEN · Seen Nov 2023
- Expected People Met Before Someone TallerPHONE SCREEN · Seen Nov 2023
Similar questions at other companies
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Logger Rate Limiter with Every-Arrival HistoryGoogle · PHONE SCREENGoogle interview questions
- Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
- Pins Violation Log QueriesPinterest · PHONE SCREENPinterest interview questions
- Resource Reconciler: Plan and Apply CreatesPerplexity AI · PHONE SCREENPerplexity AI interview questions
- Realized Gains from a Real-Estate Transaction StreamKikoff · PHONE SCREENKikoff interview questions
- Process On-Call Routing OperationsOpenAI · PHONE SCREENOpenAI interview questions
- Batched Key Fetch CallbacksAnrok · PHONE SCREEN
- Earliest Car for Each PassengerWhatNot · PHONE SCREENWhatNot interview questions
- Stateful Paginated Fetch NLyft · PHONE SCREENLyft interview questions