← 返回 ibm 的题目列表Find Common Keys in Product Recommendations
类型:online_judge
In a product recommendation system, two key-value pairs, predictions1 and predictions2, represent the recommended products shown to a user. The keys are the product names, and the values are the recommendation scores. Given two lists of product keys, pred1_keys and pred2_keys, find the common keys present in both recommendation lists and return them sorted alphabetically.
Input:
pred1_keys: a list of strings representing keys from the first recommendation list.
pred2_keys: a list of strings representing keys from the second recommendation list.
Output:
A list of strings representing the common keys in both lists.
Example:
Input: pred1_keys = ["hello", "world", "hi"], pred2_keys = ["hi", "there"]
Output: ["hi"]
Constraints:
1 <= pred1_keys.length, pred2_keys.length <= 1000
pred1_keys[i] and pred2_keys[i] consist of lowercase letters and are unique.
Example
Input
hello world hi
hi there