Amazon SDE Online Assessment 一道题


一道OA题,在 glassdoor 看到的, 没想出解法(其实是没看懂题目), 各路大神有没有会的? 看着像BFS但看结果好像又不是:Social Graph : In this problem, we want to parse a members social graup on the hot new social network. For the unfamiliar, each member in the network has n-many friends. Each of those friends has n-many more friends an on and on and on. We would like to write a program that given a socal graph, outputs each level of friends. Each friend should only be output once, at the first level they are encountered. The root friend should not be output. Input will consists of serveral lines, where each line represents a member and their friends. The final line will be the student of whom we will begin our traversal. For instance, a member and their friends will be represented as a string: A:B,C,D Where A is the member and B, C and D are the friends of A. If a member is listed without a colon, you can assume they have no friends of their own. Input 4 A:B,C,D B:A,D,E C:E,B A output: B:C,D E