← 返回 pinterest 的题目列表Top K Scored Pins Retrieval by Type Data Structure
类型:online_judge
pinterest
Design a Data Structure
Given a list of N pins, design a data structure with a retrieval function for obtaining the top k scored pins for a given pin type.
For illustration purposes, assume a Pin's string representation is of the following format: (id: w, score: x, type: y). An example input might look like this:
[(id: 0, score: 0.7, type: Static), (id: 1, score: 0.5, type: Idea), (id: 2, score: 0.2, type: Static),
(id: 3, score: 0.8, type: Idea), (id: 4, score: 0.1, type: Idea), (id: 5, score: 0.9, type: Static)]
Part 2: What changes would you make to support insertion operations? Please detail the modifications.
Example
Input
6
(0, 0.7, Static)
(1, 0.5, Idea)
(2, 0.2, Static)
(3, 0.8, Idea)
(4, 0.1, Idea)
(5, 0.9, Static)
2
Static