Flipkart | SDE 2 Machine Coding
Question Details
News Feed\t Your aim is to write a console program that can simulate a social network. Users have the following capabilities (command to be used in [-]): [post] A user...
Full Details
News Feed\t
Your aim is to write a console program that can simulate a social network.
Users have the following capabilities (command to be used in [-]):
[post] A user can post a feed item.
[follow] Users can follow other users.
[reply] A user can comment on another user\'s feed item.
[upvote/downvote] Upvote or downvote posts.
[shownewsfeed] Any user can read his news feed. News items are sorted based on the following:
Followed users : posts by followed users appear first.
Score (= upvotes - downvotes): higher the better.
Number of comments: higher the better.
Timestamp: more recent the better.
Bonus:
Allow users to comment on a comment and upvote/downvote a comment.
Display time in language like 2m ago, 1 hr ago etc.
Input and output
The input should be taken in the form of statements. The statements should consist of commands and arguments. Commands can be words like \u2018signup\u2019, \u2018newsfeed\u2019, \u2018upvote\u2019 etc.
Arguments can be separated from commands by special characters something like \u2018~\u2019. As a result a statement to reply to post 005 can look something like
reply~005~this is the reply text
You may change the input output format without changing the functionality to suit your needs.
Sample:
Input is in bold,
output is not in bold.You need to print the output of shownewsfeed for a user, whenever he logs in.
signup~lucious
signup~albus
signup~tom
login~tom
post~I am going to be the darkest dark wizard of all time
post~I am lord Voldemort btw 3:)
Login~lucious
Follow~tom
Shownewsfeed
id: 002
(0 upvotes, 0 downvotes)
tom
I am lord Voldemort btw 3:)
1994-04-19 10:11 PM
id: 001
(0 upvotes, 0 downvotes)
tom
I am going to be the darkest dark wizard of all time
1994-04-19 10:10 PM
upvote~001
reply~001~I am with you dark lord!
Shownewsfeed
id: 002
(0 upvotes, 0 downvotes)
tom
I am lord Voldemort btw 3:)
1994-04-19 10:11 PM
id: 001
(1 upvote, 0 downvotes)
tom
I am going to be the darkest dark wizard of all time
1994-04-19 10:10 PM
\tid: 003
\tLucious
\tI am with you dark lord!
\t1994-04-19 10:15 PM
login~albus
post~Happiness can be found, even in the darkest of times, if one only remembers to turn on the light
follow~tom
downvote~001
downvote~002
reply~002~LOL!
shownewsfeed
id: 001
(1 upvote, 1 downvotes)
tom
I am going to be the darkest dark wizard of all time
1994-04-19 10:10 PM
\tid: 003
\tlucius
\tI am with you dark lord!
1994-04-19 10:15 PM
id: 002
(0 upvotes, 1 downvotes)
tom
I am lord Voldemort btw 3:)
1994-04-19 10:11 PM
\tid: 005
\talbus
\tLOL!
\t1994-04-19 10:30 PM
id: 004
(0 upvotes, 0 downvotes)
albus
Happiness can be found, even in the darkest of times, if one only remembers to turn on the light
1994-04-19 10:28 PM
Guidelines:
Input can be read from a file or STDIN or coded in a driver method.
Output can be written to a file or STDOUT.
Feel free to store all interim/output data in-memory.
Restrict internet usage to looking up syntax
You are free to use the language of your choice.
Save your code/project by your name and email it. Your program will be executed on another machine. So, explicitly specify dependencies, if any, in your email.
Expectations:
Code should be demo-able (very important). Code should be functionally correct and complete.
At the end of this interview round, an interviewer will provide multiple inputs to your program for which it is expected to work
Code should handle edge cases properly and fail gracefully. Add suitable exception handling, wherever applicable.
Code should have good object-oriented design.
Code should be readable, modular, testable and extensible. Use intuitive names for your variables, methods and classes.
It should be easy to add/remove functionality without rewriting a lot of code.
Do not write monolithic code.
Don\u2019t use any databases.
About This Question
This is a reported interview question from a intuit interview for a pm role (intern level) during the technical round reported in 2025.
It covers the following topics: Oop .
Difficulty rating: Easy