## Friday, August 20, 2010

### Solution to the Facebook programming puzzle of "mutual likes"

Disclaimer, you need to create your own Facebook working access_token and replace it in the below urls
`{"data": [  {     "name": "",     "id": "31913"  },  {`
• This is what you like [ https://graph.facebook.com/me/friends?access_token= ]
`{"data": [   {      "name": "Information theory",      "category": "Field of study",      "id": "107921045903425",      "created_time": "2010-08-20T17:47:47+0000"   },   {      "name": "Data modeling",      "category": "Interest",      "id": "107298675966720",      "created_time": "2010-08-20T17:47:18+0000"   },   {      "name": "Statistical inference",      "category": "Interest",      "id": "108195032537847",      "created_time": "2010-08-20T17:46:49+0000"   },`
• This is what my friend Tony likes [ https://graph.facebook.com/1452108295/likes?access_token=]
`{"data": [   {      "name": "BB King",      "category": "Musicians",      "id": "43780515976",      "created_time": "2010-07-20T19:57:00+0000"   },   {      "name": "Luciano Moggi",      "category": "Public_figures_other",      "id": "56461948713",      "created_time": "2010-07-09T08:12:34+0000"   },   {      "name": "Bing Jobs Europe",      "category": "Technology",      "id": "132723843410879",      "created_time": "2010-06-30T15:13:13+0000"   },   {      "name": "10 Worst Tattoo Spelling Mistakes EVER!!!",      "category": "Public figure",      "id": "133641006660295",      "created_time": "2010-06-27T12:02:37+0000"   },`
Therefore the solution is to enumerate all your friends, get their ids, get what they likes and intersect with what you like.

Since the puzzle requires to "The problem is to find the friend who shares the most number of items with you", you can simply store all your "like ids" and then, for each friend, count how many likes ids you have in common. You just need to store the current maximum, and the correspondent friend id.