Order Queries by Shortest Processing Time
Updated
Problem statement
Given queryIntervals, return the original query indices in an order that minimizes the sum of query completion times.
For this exercise, assume an interval [start,end] describes a query whose processing duration is end-start. The endpoints do not constrain its start time. All queries are available at processing time 0, and one worker processes one whole query at a time without preemption or idle gaps.
The completion time of a query is the total duration of that query and every query before it in the chosen order. If multiple optimal orders differ only in queries with equal durations, place their original indices in ascending order.
Return every zero-based index exactly once. An empty input returns an empty array. The interval data has already been obtained from the supplied input interface; no model or network call is required.
Function
queryProcessingOrder(queryIntervals: int[][]) → int[]Examples
Example 1
queryIntervals = [[0,3],[10,11],[2,4]]return = [1,2,0]The durations are 3, 1, and 2. The returned order completes queries at times 1, 3, and 6, with total completion time 10.
Example 2
queryIntervals = [[5,7],[0,2],[9,11]]return = [0,1,2]All durations are 2, so every order has the same objective. The required ascending-index tie rule selects 0, 1, 2.
Example 3
queryIntervals = []return = []There are no queries to schedule, so the order is empty.
Constraints
- For this exercise, assume
0 <= queryIntervals.length <= 100000. - Every row contains two integers with
0 <= start < end <= 1000000000. - Rows may be unsorted, overlapping, nested, or identical; every row is a separate query.
More Scale AI Phone Screen questions
- Four-Player Trick-Taking Card Game SimulationOA · PHONE SCREEN · Seen Aug 2026
- Task Processor: Dependencies and DeadlinesPHONE SCREEN · Seen Aug 2026
- Best Poker Category with a JokerPHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2026
- Free Time for Every Meeting RoomPHONE SCREEN · Seen Apr 2026
- Free Windows Between Busy IntervalsOA · PHONE SCREEN · Seen Apr 2026
- Party Time by Town and Quiet Gaps by CityPHONE SCREEN · Seen Jan 2026
- Party Windows and Dead Zone TimePHONE SCREEN · Seen Oct 2025
- Overlap Duration of Two Time IntervalsPHONE SCREEN · Seen Jun 2025
- Multi-Head Attention BlockPHONE SCREEN · Seen Mar 2025
- Top-K SamplerPHONE SCREEN · Seen Mar 2025
Similar questions at other companies
- Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
- Maximum Number of Events That Can Be AttendedByteDance · PHONE SCREENByteDance interview questions
- Remove the Fewest Magic BeansThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
- Aggressive CowsAmazon · PHONE SCREEN
- Minimize Range After Three ChangesDRW · PHONE SCREENDRW interview questions
- Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
- Experiment Bucket Allocation and RebalancingPinterest · PHONE SCREENPinterest interview questions
- Maximum Number of Events That Can Be AttendedSnowflake · PHONE SCREENSnowflake interview questions
- Minimum Appointment Cancellations with a Required BreakMaven Clinic · PHONE SCREENMaven Clinic interview questions
- Two City Scheduling with an Odd Candidate CountBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions