Service Request Load
MediumGraphs ยท Robinhood
calls is a list of [caller, callee] pairs between the names in services, and no chain of calls loops back on itself. One request arrives at service entry. Each time a service receives a request, it sends one request to every service it calls; a pair listed twice is two separate calls.
Return a dictionary giving, for every service, the total number of requests it receives. entry counts the original request, and a service that never receives one maps to 0.
Example 1
- Input:
- services = ["gateway", "auth", "cart", "db", "audit"], calls = [["gateway", "auth"], ["gateway", "cart"], ["auth", "cart"], ["auth", "db"], ["cart", "db"]], entry = "gateway"
- Output:
- {"gateway": 1, "auth": 1, "cart": 2, "db": 3, "audit": 0}
- Explanation
cartis called bygatewayand byauth, so it receives 2 and sends 2 todb. Adding 1 fromauthgivesdb3.auditis never called.
Example 2
- Input:
- services = ["solo"], calls = [], entry = "solo"
- Output:
- {"solo": 1}
Example 3
- Input:
- services = ["a", "b", "c"], calls = [["a", "b"], ["a", "b"], ["b", "c"]], entry = "a"
- Output:
- {"a": 1, "b": 2, "c": 2}
- Explanation
- The repeated pair means
asendsbtwo requests, and each of them makesbsend one toc.
Constraints
1 <= services.length <= 200, all names distinct and case-sensitive0 <= calls.length <= 1000, every name incallsis inservices, and no service calls itselfentryis inservices- Every returned count is at most
10^15