Design a follow graph for a social network. A follow is directional: if ada follows bob, Bob gains a follower, but Bob does not automatically follow Ada. Both users must still reflect the same relationship consistently.
The provided FollowGraph class supports these operations:
FollowGraph() creates a graph with no users.boolean addUser(String name) adds a user and returns true. A name already present is refused with false.boolean follow(String followerName, String targetName) records that the first user follows the second and returns true. It changes nothing and returns false when either name is unknown, the names refer to the same user, or the relationship already exists.boolean unfollow(String followerName, String targetName) removes the follow and returns true. It changes nothing and returns false when either name is unknown or the follow does not exist.String[] following(String name) returns who that user follows, in the order the follows were made.String[] followers(String name) returns who follows that user, in the order those follows were made.boolean isFollowing(String followerName, String targetName) returns whether the first follows the second.Following and unfollowing only create or remove a relationship. Both users continue to exist and retain all their other connections.
Your task is to implement the User class expected by the provided graph. Do not modify FollowGraph. Each user should store references to the users they follow and the users who follow them. A single startFollowing or stopFollowing call must update both sides of the relationship.
Input:
Output:
Explanation: Ada's following list gains Bob, and Bob's followers list gains Ada. These are two views of the same directional relationship, and one follow call updates both.
Input:
Output:
Explanation: Ada cannot follow herself, and ghost does not identify a registered user. Both operations return false and leave Ada's following list empty.
1 <= name.length <= 20100 calls will be made across all methods.Full marks when one call updates both sides so the following and followers lists can never disagree, and unfollowing removes both entries. Lose points heavily when the caller has to update the second side separately, or when only one direction is maintained.
Full marks when users are separate objects holding references to each other, and both users survive a follow being removed. Lose points when a user stores the other's name as a string, or when the graph is kept as a table outside the users rather than as links between them.
Full marks when self-follows, unknown names and repeat follows are each refused without changing anything, and lists report insertion order. Lose points when a refused call still mutates a list, or for printing to stdout.
Passing every test is not enough on its own. A submission is accepted only when the design also clears the bar.
| Call | Returns |
|---|---|
| new FollowGraph() | null |
| addUser("ada") | true |
| addUser("bob") | true |
| follow("ada", "bob") | true |
| following("ada") | ["bob"] |
| followers("bob") | ["ada"] |
| isFollowing("ada", "bob") | true |
Following adds the target to one user's following list and the follower to the other's followers list, so a single call updates both sides.
Run checks these cases. Submit also runs a larger hidden set.

