Tech screening was a task to generate all possible permutations given a set of rules. Main coding challenge: graph traversal problem (DFS or BFS is enough). System design: Design an online game of a Tick-Tak-Toe.
Implement the permutation portion as generate_permutations(items, rules). items is a list of unique strings, and rules[item] lists permitted next items. A permutation must use every item exactly once, follow each selected directed edge, and end at an item with no permitted next items. Return results in DFS traversal order. Missing rule keys mean the item is terminal.
def generate_permutations(items, rules):