AlgoMaster Logo
AlgoMasterSolve Little's Laweasy

Solve Little's Law

easy

Little's Law connects three average quantities in a stable system:

Design a LittlesLawCalculator class:

  • LittlesLawCalculator() creates a stateless calculator.
  • double solve(double throughput, double concurrency, double latencySeconds) returns the missing quantity, rounded to 5 decimal places.

Exactly one argument is -1:

  • throughput is completed requests per second.
  • concurrency is the average number of requests in the system.
  • latencySeconds is the average time one request spends in the system, measured in seconds.

The other two arguments are positive. Detect the -1 argument, rearrange Little's Law, and round only the final result. Every call is independent.

Example 1:

Input:

Output:

Explanation: The service completes 100 requests per second and each request spends 0.05 seconds inside it, so average concurrency is 100 × 0.05 = 5.

Example 2:

Input:

Output:

Explanation: With 5 requests in flight and 0.05-second latency, throughput is 5 / 0.05 = 100 requests per second.

Constraints

  • Exactly one argument equals -1.
  • Each known argument is between 10^-5 and 10^4, inclusive.
  • latencySeconds is expressed in seconds whenever it is known.
  • The system is stable, so its long-run arrival and completion rates match.
  • Round the final answer to 5 decimal places.
  • Answers are accepted within 10^-5 of the expected result.
  • At most 100 calls are made to solve.
Hints

Loading...
CallReturns
new LittlesLawCalculator()null
solve(100, -1, 0.05)5

At 100 requests per second and 0.05 seconds per request, the average concurrency is 100 × 0.05 = 5 requests.

Run checks these cases. Submit also runs a larger hidden set.