← 返回 snapchat 的题目列表Combinations of Elements Using Recursive Mapping
类型:online_judge
Given an array of integers and a mapping dictionary, create a function to output all combinations of the dictionary's values corresponding to the elements of the array. Solve this problem recursively.
Input
array: A list of unique integers, e.g., [1, 2, 3].
mapping: A dictionary where keys are integers, and values are lists of strings, e.g., {1: ['a', 'b'], 2: ['c', 'd'], 3: ['e', 'f']}.
Output
The return value is a two-dimensional list containing all possible combinations.
Example
Input:
array = [2, 3]
mapping = {1: ['a', 'b'], 2: ['c', 'd'], 3: ['e', 'f']}
Output:
[['c', 'e'], ['c', 'f'], ['d', 'e'], ['d', 'f']]
Example
Input
[2, 3]
{
1: ['a', 'b'],
2: ['c', 'd'],
3: ['e', 'f']
}