Follow Graph
Asked at OpenAI
Reported by the problem's creator, not verified
Build a small social network as the class SocialGraph. Users are identified by strings, compared as ordinary case-sensitive strings ("u10" < "u2"). Following is directed: follow("ann", "bob") means ann follows bob and says nothing about bob following ann. A user who has never been mentioned follows nobody.
Each test drives one SocialGraph() instance through a sequence of calls and checks every return value. Each example shows init (constructor arguments) and operations, a list of [method, [args]] calls; the output lists every call's return value.
Examples
Example 1
Input: init =
[], operations =[["follow",["ann","bob"]],["follow",["ann","cy"]],["follow",["ann","bob"]],["follow",["ann","ann"]],["followees",["ann"]],["unfollow",["ann","bob"]],["unfollow",["ann","bob"]],["unfollow",["bob","ann"]],["followees",["ann"]],["followees",["bob"]],["followees",["zed"]],["follow",["bob","ann"]],["follow",["ann","bob"]],["followees",["ann"]],["followees",["bob"]]]Output:
[true,true,false,false,["bob","cy"],true,false,false,["cy"],[],[],true,true,["bob","cy"],["ann"]]Explanation: Following someone already followed, or following yourself, returns False and changes nothing.
followeeslists who a user follows in alphabetical order, and an unknown user follows nobody. Unfollowing a missing edge returns False, and edges are directed, so ann following bob says nothing about bob following ann.