A harder engineering round asks you to defend several invariants at once. Dependency ordering must remain deterministic when tasks become ready together. Admission must distinguish old accepted work from rejected attempts. Cancellation must finish the tasks it owns.
This set uses original service scenarios and runnable checks. Some problems are short to state but require careful state ownership, completion accounting or boundary handling. There is no named-company attribution and no copied problem statement. Work from the supplied contract, choose a data structure and explain why each update preserves the invariant. The async tasks execute in the workspace; graph and admission tasks use deterministic data. Hidden variants include empty work, duplicate evidence and exact boundaries rather than relying on an elapsed-time contest.
import json
def process_payload(payload: str) -> str:
data = json.loads(payload)
import heapq
graph = {node:set() for node in data['tasks']}
indegree = {node:0 for node in graph}
for before, after in data['edges']:
if after not in graph[before]:
graph[before].add(after)
indegree[after] += 1
ready = [node for node in graph if indegree[node] == 0]
heapq.heapify(ready)
result = []
while ready:
node = heapq.heappop(ready)
result.append(node)
for child in graph[node]:
indegree[child] -= 1
if indegree[child] == 0:
heapq.heappush(ready,child)
return json.dumps(result if len(result) == len(graph) else None,separators=(',',':'))
A ready-task heap resolves ties, duplicate edges count once, and cycles return null. Build a directed graph with unique edges and an indegree count for each declared task. The heap makes the stable tie policy explicit; duplicate edges must not add a second prerequisite.