
Meta network operations automation often pulls device state from multiple REST endpoints where some requests depend on others. Given a set of API calls, their dependencies, and a per-time-slot rate limit, compute the earliest execution schedule or report that the workflow is impossible.
Implement a function schedule_api_calls(calls, dependencies, rate_limit).
calls: a list of unique strings, where each string is a REST operation ID such as "get_fabric_health".dependencies: a list of pairs [a, b] meaning call a must complete before call b can start.rate_limit: a positive integer representing the maximum number of calls that can be executed in one time slot.Return a list of lists, where each inner list contains the call IDs executed in that time slot. If the dependency graph contains a cycle, return [].
When multiple calls are available in the same slot, execute them in lexicographically sorted order for deterministic output.
Example 1
Input: calls = ["auth", "devices", "ports", "alerts"], dependencies = [["auth", "devices"], ["auth", "alerts"], ["devices", "ports"]], rate_limit = 2
Output: [["auth"], ["alerts", "devices"], ["ports"]]
Explanation: auth must run first. Then both alerts and devices are ready and fit in the same slot.
Example 2
Input: calls = ["a", "b", "c"], dependencies = [["a", "b"], ["b", "c"], ["c", "a"]], rate_limit = 2
Output: []
Explanation: The dependencies form a cycle, so no valid schedule exists.
1 <= len(calls) <= 10^50 <= len(dependencies) <= 2 * 10^51 <= rate_limit <= len(calls)1 to 50calls = ["auth", "devices", "ports", "alerts"], dependencies = [["auth", "devices"], ["auth", "alerts"], ["devices", "ports"]], rate_limit = 2Output[["auth"], ["alerts", "devices"], ["ports"]]WhyOnly `auth` is initially ready. After it completes, both `alerts` and `devices` are available, and `ports` must wait until `devices` finishes.calls = ["a", "b", "c"], dependencies = [["a", "b"], ["b", "c"], ["c", "a"]], rate_limit = 2Output[]WhyThe graph contains a cycle, so no call can be fully scheduled in a valid dependency order.calls = ["login", "health", "inventory", "metrics"], dependencies = [], rate_limit = 3Output[["health", "inventory", "login"], ["metrics"]]WhyWith no dependencies, all calls are immediately available and are scheduled in lexicographic order, limited to 3 per slot.1 <= len(calls) <= 10^50 <= len(dependencies) <= 2 * 10^51 <= rate_limit <= len(calls)All call IDs are unique strings of length 1 to 50Every dependency references valid call IDsdef schedule_api_calls(calls, dependencies, rate_limit):