Untitled
unknown
plain_text
2 years ago
2.0 kB
8
Indexable
Let’s implement a few functions used in social media. 1. Upload a post. Each post has a timestamp indicating the time at which they were uploaded. 2. “Follow” other users. Once you follow them, you can see their posts. 3. Add “Like” to a particular post. 4. Given that a user A “follows” another user B, show A up to 10 posts in descending order of priority from the one with a higher priority between the two posts uploaded by A and B each. The following set of rules determines the priority level of each post: 1. The post that was uploaded 1,000 seconds or less ago has a higher priority than the post that was not. 2. Among the posts that were uploaded 1,000 seconds or less ago, the one with the biggest number of “likes” has the highest priority. 3. Among the posts that were uploaded 1,000 seconds or less ago and have the same number of “likes”, the one with a larger “timestamp” has a higher priority. 4. As for the posts that were uploaded more than 1,000 seconds ago, the one with a larger “timestamp” has a higher priority. Let’s take a look at a simple example below to see how the priority level of each post is determined. There are 2 users with the uID of 1 and 2 each. They “follow” one another. Assume that the user uID 1 has uploaded four posts as shown in [Table 1]. pID timestamp like 1 99 10 2 100 2 3 300 5 4 400 1 [Table 1] If the current “timestamp” is 500, the user uID 2 will see the posts of the user uID 1 in order of pId 1, 3, 2, and 4. Here, you should return these four values. If the current “timestamp” is 1,100, the user uID 2 will see the posts of the user uID 1 in order of pId 3, 2, 4, and 1. Here, you should return these four values. In the latter case, the post pID 1 was uploaded more than 1,000 seconds ago. Therefore, it has a lower priority than the other posts of the pID 2, 3, and 4.
Editor is loading...