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
  • These are your friends [ https://graph.facebook.com/me/friends?access_token= ]
{
"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.

3 comments:

  1. Yeah, I ended up doing this just for fun too. I think they should have made the algorithmic part of the problem a little more challenging.

    Maybe that's very Facebook of them though. Where Google might have thrown up some challenging graph theory problem, Facebook does a puzzle that focuses on getting something done quickly.

    ReplyDelete
  2. here a nice pratical talk about graphs (huge graphs)

    http://www.facebook.com/home.php?#!/video/video.php?v=432864835468

    ReplyDelete
  3. Thanks, Antonio. To return the favor, here's a pointer to some thoughts on the difference between Facebook and Google's engineering environments by someone who worked at both. As I said, Facebook focuses on getting things done quickly (which very often is a good thing).

    http://www.25hoursaday.com/weblog/2010/08/27/LessonsFromGoogleWaveAndRESTVsSOAPFightingComplexityOfOurOwnChoosing.aspx

    ReplyDelete