← Questions

Pick the most profitable repeated query

0
SnowflakeCodingLast asked Jan 2026

A data warehouse has a time budget of k minutes and n query types. Query type i takes times[i] minutes per run and earns profits[i] per completed run.

You must commit to one query type and run it back to back, as many whole runs as fit in k minutes. A run that would end after k minutes earns nothing and cannot be started.

Implement:

def max_profit_query(times: list[int], profits: list[int], k: int) -> list[int]:
    ...

Return [best_total_profit, index] for the query type with the highest total profit. If several types tie, return the smallest index. If no type can run even once within k minutes, return [0, -1].

Constraints

  • 0 <= n <= 10^5, len(times) == len(profits)
  • 1 <= times[i] <= 10^9, 0 <= profits[i] <= 10^9
  • 0 <= k <= 10^12

Example 1

times = [6, 5], profits = [7, 5], k = 10
Output: [10, 1]

Type 0 fits once (7). Type 1 fits twice (10). Type 0 earns more per minute, but its leftover 4 minutes are wasted.

Example 2

times = [2, 4, 1], profits = [4, 8, 2], k = 8
Output: [16, 0]

Every type earns 16, so the smallest index wins.

Example 3

times = [11, 20], profits = [100, 5], k = 10
Output: [0, -1]

Reconstructed from the reported question; details may differ from what interviewers ask.

Write and test your solution herePython in your browser, the question's tests level by level, saved for you.Sign in to start coding