SHARE
TWEET

Twilio Phone Interview

a guest Feb 26th, 2012 5,316 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
Top