← 返回 microsoft 的题目列表Top K Relevant Apps by Keyword Scores
类型:online_judge
Given a set of apps and per-keyword relevance scores, return the Top K most relevant apps.
Input
An integer K.
A JSON/dictionary apps where each key is an app name (string) and each value is a map keyword -> score (float).
Example:
{
"github": {"diff": 0.3, "code review": 0.8},
"jira": {"ticket": 0.6, "bug": 0.4}
}
Relevance definition (concrete for implementation)
Overall relevance of an app = the maximum score among its keywords.
Sort apps by overall relevance descending; break ties by app name lexicographically ascending.
Output
Return a list of app names of length K (if total apps < K, return all).
Constraints
1 <= N <= 500 (number of apps)
1 <= K <= N
Each app has at least one keyword score
Scores are non-negative floats
Test Cases
Input:
K=2
apps={"github":{"diff":0.3,"code review":0.8},"jira":{"ticket":0.6,"bug":0.4},"notion":{"doc":0.7}}
Output:
["github","notion"]
Input:
K=3
apps={"a":{"k1":1.0},"b":{"k1":1.0},"c":{"k1":0.9}}
Output:
["a","b","c"]
Input:
K=5
apps={"slack":{"m":0.2},"teams":{"m":0.4}}
Output:
["teams","slack"]
Input:
K=1
apps={"x":{"a":0.0,"b":0.0},"y":{"a":0.1}}
Output:
["y"]
Input:
K=2
apps={"z":{"k":0.5},"aa":{"k":0.5},"b":{"k":0.5}}
Output:
["aa","b"]
Example
Input
K=2
apps={"github":{"diff":0.3,"code review":0.8},"jira":{"ticket":0.6,"bug":0.4},"notion":{"doc":0.7}}
Output
["github","notion"]