Implement Posting and Follow-Based Recent Tweet Feeds

Quick Overview

Implement Posting and Follow-Based Recent Tweet Feeds. Implement Twitter with postTweet, getNewsFeed, follow and unfollow. A feed contains at most ten most recent tweet IDs posted by the user or their currently foll

Implement Posting and Follow-Based Recent Tweet Feeds

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Implement Twitter with postTweet, getNewsFeed, follow and unfollow. A feed contains at most ten most recent tweet IDs posted by the user or their currently followed users, newest first. Tweet IDs are unique identifiers, not chronological values. Follow/unfollow alter whose stored tweets are eligible; preserve all constructor and method signatures. ```cpp class Twitter { public: Twitter(); void postTweet(int userId, int tweetId); vector<int> getNewsFeed(int userId); void follow(int followerId, int followeeId); void unfollow(int followerId, int followeeId); }; ``` ### Examples ```text Twitter(); postTweet(1,8); follow(1,2); postTweet(2,3); getNewsFeed(1) -> [3,8]; unfollow(1,2); getNewsFeed(1) -> [8] Twitter(); getNewsFeed(4) -> [] ``` ### Constraints - User/follower/followee IDs lie in [1,500]. - Tweet IDs lie in [0,10000] and all posted IDs are unique. - At most 30000 total method calls occur. - A user cannot follow themself.

Overview: Implement Posting and Follow-Based Recent Tweet Feeds. Implement Twitter with postTweet, getNewsFeed, follow and unfollow. A feed contains at most ten most recent tweet IDs posted by the user or their currently foll

Google logo
Google
Source window: 0–6 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Implement Twitter with postTweet, getNewsFeed, follow and unfollow. A feed contains at most ten most recent tweet IDs posted by the user or their currently followed users, newest first. Tweet IDs are unique identifiers, not chronological values. Follow/unfollow alter whose stored tweets are eligible; preserve all constructor and method signatures.

class Twitter {
public:
    Twitter();
    void postTweet(int userId, int tweetId);
    vector<int> getNewsFeed(int userId);
    void follow(int followerId, int followeeId);
    void unfollow(int followerId, int followeeId);
};

Examples

Twitter(); postTweet(1,8); follow(1,2); postTweet(2,3); getNewsFeed(1) -> [3,8]; unfollow(1,2); getNewsFeed(1) -> [8]
Twitter(); getNewsFeed(4) -> []

Constraints

  • User/follower/followee IDs lie in [1,500].
  • Tweet IDs lie in [0,10000] and all posted IDs are unique.
  • At most 30000 total method calls occur.
  • A user cannot follow themself.