Tell me about a coding and Terraform scenario you faced where you had to solve a LeetCode-style problem and a Terraform task. For the coding portion, implement resource_apply_order(resources, dependencies) to return a deterministic order in which Terraform resources can be created, or [] if dependencies contain a cycle. resources is a list of unique names, and dependencies maps each resource to prerequisite resource names.
def resource_apply_order(resources, dependencies):