Guest User

Twilio Phone Interview

a guest
Feb 26th, 2012
5,732
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Tweet Search Engine
  2.     *Navigation bar at top of page - contains links to “Search” and “Insert Tweet”
  3.     Search
  4.         *Can search by word
  5.         *Once query is submitted, return list of all matching tweets
  6.     Insert
  7.         *”Tweets” can be inserted into database
  8.  
  9. global $db = array();
  10.  
  11. interface Tweet { content:String }
  12.  
  13. function save(Tweet $doc) { // String
  14.   $words = explode(“ “, $doc->content);
  15.   foreach ($words as $word)
  16.   {
  17.     if (!isset($db[$word]))
  18.       $db[$word] = array($doc);
  19.     else if (!in_array($doc, $db[word]))
  20.       array_push($db[$word], $doc);
  21.   }
  22. }
  23.  
  24. $tweet = Tweet(“this this this is a tweet”);
  25. $tweet2 = Tweet(“this is another”);
  26. save($tweet);
  27. save($tweet2);
  28. array(
  29.   “this” => array($tweet, $tweet2)),
  30.   array(“is”, $tweet),
  31.   array(“a”, $tweet),
  32.   array(“tweet”, $tweet),
  33.   array(“this”, $tweet2),
  34. )
  35.  
  36. function retrieve($keyword) { // String -> [Tweet]
  37.   if (isset($db[$keyword])
  38.     return $db[$keyword];
  39.   else return array();//
  40. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×