Question
Goal: Write an HTTP service which accepts a graph of people where edges represent friendship relationships. Return the suggested edges which would create direct friend
Goal:
Write an HTTP service which accepts a graph of people where edges represent friendship relationships. Return the suggested edges which would create direct friend relationships between two people who currently are at most one friend away two people who are friends of a friend (FOAFs).
Problem:
Receive as input an array of friend relationships.
Return a set of arrays each representing a new suggested friend relationship.
Example input:
{ inList : [
{ friends : [ Albert, Betty ] },
{ friends : [ Betty, Cathy ] },
{ friends : [ Cathy, Denis ] },
{ friends : [ Denis, Albert ] },
{ friends : [ Tony, Bruce ] }
] }
Example output:
{ outList : [ [ Albert, Cathy ] , [ Betty, Denis ] ] }
Do not duplicate the suggestions (in the example above, do not also suggest [ Cathy, Albert ]. If no new friend relationships can be suggested, return the empty array. { "outList" : [ ] }
Erroneous input (e.g. malformed JSON) should be handled gracefully.
In java Preferably.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started