Sorting social media feeds by user and timestamp enhances user experience by ensuring posts are organized in a meaningful way. You are given a social media feed with entries containing various data, timeStamp, userId, and post, and your task is to sort these entries first based on user and then chronologically.
Write a function sortSocialMediaFeed
that takes in a list of string, where each string is comma-separated value representing a post with timeStamp (a string representing Unix time), userId, and post. The function should return the feed sorted first by userId and then by timeStamp for each user.
Function Description
Complete the function sortSocialMediaFeed
in the editor.
sortSocialMediaFeed
has the following parameter(s):
string feed[n]
: a list of comma-separated strings where each string contains timeStamp, userId, and post, representing the data of social media posts
Returns
string[n]
: the social media posts ordered first by userId and then by timeStamp
Example 1:
Input: feed = ["1654162021,user2,Post A", "1654163021,user1,Post B", "1654146021,user1,Post C", "1654165021,user2,Post D"]
Output: ["1654163021,user1,Post B", "1654146021,user1,Post C", "1654162021,user2,Post A", "1654165021,user2,Post D"]
Explanation:First, the feed is sorted by userId, resulting in user1, user2, user1, user2. Then, within those two categories, they are sorted by timeStamp. For user1, "Post B" came before "Post C." For user2, "Post A" came before "Post D."
๐
๐

input:
output: