Social Media Feed
Learn this problemProblem statement
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 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 a list of strings. Each string is a comma-separated value representing a post with timeStamp (a string representing Unix time), userId, and post. Return the feed sorted first by userId and then by timeStamp for each user.
Function
sortSocialMediaFeed(feed: String[]) → String[]Examples
Example 1
feed = ["1654162021,user2,Post A", "1654163021,user1,Post B", "1654164021,user1,Post C", "1654165021,user2,Post D"]return = ["1654163021,user1,Post B", "1654164021,user1,Post C", "1654162021,user2,Post A", "1654165021,user2,Post D"]First, the feed is sorted by userId, resulting in user1, user1, user2, user2. Within each user, the posts are then sorted by timeStamp. For user1, “Post B” comes before “Post C.” For user2, “Post A” comes before “Post D.”
Constraints
🍅🍅More Tiktok problems
- Count Access Code PairsOA · Seen Jul 2026
- Count Key ChangesOA · Seen Jul 2026
- Travel Distance on ScootersOA · Seen Jul 2026
- Count Skipped Numbers After SubtractionsOA · Seen Jul 2026
- Obstacle Placement QueriesOA · Seen Jul 2026
- Repeated Grouped Digit SumOA · Seen Jul 2026
- Count Cyclic Digit PairsOA · Seen Jun 2026
- Event ID Check Completion TimesOA · Seen Jun 2026