


‘POST’(USERID, TWEETID) tells that a user having ID as USERID has posted a tweet having ID as TWEETID.
‘GET_FEED’( ‘USERID’ ) returns the list of 10 most recent tweet IDs in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user themself. Tweets must be ordered from most recent to least recent.
‘FOLLOW(USERID, FOLLOWERID) tells that user is followed by the user having ID as ‘FOLLOWERID’.
UNFOLLOW(USERID, FOLLOWERID) tells that the user ‘FOLLOWERID’ has unfollowed the user.
The first line of the input contains an integer, 'T,’ denoting the number of test cases.
The first line of each test case contains a single integer, 'N’, denoting the number of function calls.
Next ‘N’ lines of each test case contain an integer denoting the function type followed by the parameter list.
Type 1 denotes POST().
Type 2 denotes GET_FEED().
Type 3 denotes FOLLOW().
Type 4 denotes UNFOLLOW().
For each test case, output the lists returned by the GET_FEED() function.
Print the output of each test case in a separate line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 10000.
1 <= ‘USERID’ <= 500 .
Time limit: 1 sec
In this approach, we will use a matrix M of size 501*501 .M[i][j] will be 1 is the user ‘i’ is followed by user ‘j’ otherwise 0. And we will use an array ‘TWEETS’ having two fields {tweetID,userID} to store all the tweets. For follow() and unfollow() functions we will update the values of matrix M.For get_Feed() function, we will iterate the TWEETS array from backward and find the suitable tweets for the user.
In this approach, we will define a map TWEETS where TWEETS[U] will store the list of tweets of USER ‘U’.The tweet data will have two fields {TWEETID, TIME}. We will also maintain a map FOLLOWING.FOLLOWING[i] will contain the set of all users that i is following. In GET_FEED() function, we will exact the list of all users whom the current user is following and pick the 10 recent tweets using the help of the TWEETS map.
Design Tic-Tac-Toe
Top K Stocks to Sell
Special Queue
Dot Product of Two Sparse Vectors
LFU Cache
LFU Cache
LFU Cache
LFU Cache
LFU Cache
LFU Cache