As reported: Okta Senior Software Engineer loop (Oct 2026). HR announced three DSA rounds and one hiring-manager + LLD round, but round 1 was this design problem: create tweets, follow, unfollow, and fetch a user's top 10 news feed sorted by time. After an in-memory class design (user id, tweet id, timestamp; follow / unfollow / news-feed methods), the interviewer asked for an implementation backed by a database, and no code was to be written until the schema and the indexes for every method were clear.
Design a simplified Twitter. This is LeetCode 355 — Design Twitter:
Twitter()creates an empty service.postTweet(userId, tweetId)— useruserIdposts a new tweet with the unique idtweetId. Each call is later than every call before it.getNewsFeed(userId)— the ids of the 10 most recent tweets in the user's news feed, most recent first. The feed holds tweets posted by the user and by everyone the user follows.follow(followerId, followeeId)—followerIdstarts followingfolloweeId.unfollow(followerId, followeeId)—followerIdstops followingfolloweeId.
Example
["Twitter","postTweet","getNewsFeed","follow","postTweet","getNewsFeed","unfollow","getNewsFeed"]
[[],[1,5],[1],[1,2],[2,6],[1],[1,2],[1]]
-> [null,null,[5],null,null,[6,5],null,[5]]
User 1 sees only tweet 5; after following user 2, tweet 6 (newer) comes first; after unfollowing, only tweet 5 again.
Second part (database). Then implement the same four operations on top of a relational database: give the tables, the primary keys and the indexes each method relies on, and the query each method runs.
Clarifications
- Following yourself, following someone twice, or unfollowing someone you don't follow changes nothing.
- A user always sees their own tweets.
Constraints: 1 ≤ userId, followerId, followeeId ≤ 500; 0 ≤ tweetId ≤ 10^4; at most 3 · 10^4 calls in total.
Code runner format: two lines, LeetCode's format: the list of operations (starting with "Twitter"), then the list of their argument lists. Implement the class Twitter with postTweet, getNewsFeed, follow and unfollow; the harness prints the list of return values (null for methods that return nothing).