Your question is Topological Sort for Dependencies. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Samsung Ads services and campaign-processing components must be deployed only after their prerequisites. Given component names and directed dependency pairs, return a valid deployment order. If multiple components are available, choose the lexicographically smallest name to make deployments reproducible. Return an empty list when the dependencies contain a cycle.
Implement resolve_dependencies(components, dependencies). components is a list of unique strings. Each item in dependencies is a two-element list [prerequisite, component], meaning prerequisite must appear earlier than component. Return a list containing every component exactly once, or [] if no complete ordering exists.
The result must be deterministic, including when several valid orders exist. Every dependency pair refers to names in components. Duplicate dependency pairs may appear and must not increase the required ordering more than once.
def resolve_dependencies(components, dependencies):