Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. You have a list conversations, in which each element is a conversation that is represented as an array of words. You need to create a chatbot that will complete a conversation that is currently in progress, currentConversation.
  2.  
  3. To do that, the chatbot must find the conversation from the given list that has the largest number of unique words that match with words from the currentConversation. If there are several conversations that match this condition, the chatbot should use the one that appears first in conversations. If no conversation from the list contains any matching words from currentCoversation, the chatbot should leave currentConversation as it is.
  4.  
  5. If there is a conversation that can complete currentConversation, the chatbot should find the first word in it that appears after all the matching words. The chatbot should then append this word, along with all the words that follow it in that conversation, to currentConversation.
  6.  
  7. Return the final state of currentConversation.
  8.  
  9. Example
  10.  
  11. For
  12. conversations = [
  13. ["where", "are", "you", "live", "i", "live", "in", "new", "york"],
  14. ["are", "you", "going", "somewhere", "tonight", "no", "i", "am", "too", "tired", "today"],
  15. ["hello", "what", "is", "your", "name", "my", "name", "is", "john"]]
  16. and currentConversation = ["hello", "john", "do", "you", "have", "a", "favorite", "city", "to", "live", "in", "yes", "it", "is"], the output should be
  17. chatBot(conversations, currentConversation) = ["hello", "john", "do", "you", "have", "a", "favorite", "city", "to", "live", "in", "yes", "it", "is", "new", "york"].
  18.  
  19. The second conversation has only one matching word, "you". But the other two conversations both have three unique matching words. In the first conversation, the matches are "you", "live", and "in". In the third conversation, the matches are "hello", "john", and "is". Since we have two options that could complete our current conversation, we should choose the one that appears earlier in the list, so we use the first conversation. In that conversation, the last matching word is "in", so we add the last two words, "new" and "york", to currentConversation to complete it.
  20.  
  21. For
  22. conversations = [
  23. ["lets", "have", "some", "fun"],
  24. ["i", "never", "get", "it"],
  25. ["be", "aware", "of", "this", "house"],
  26. ["he", "will", "call", "her"]]
  27. and currentConversation = ["can", "you", "please"], the output should be
  28. chatBot(conversations, currentConversation) = ["can", "you", "please"].
  29.  
  30. None of the conversations have any words that match words in currentConversation, so we add nothing to it.
  31.  
  32. Input/Output
  33.  
  34. [execution time limit] 0.5 seconds (cpp)
  35.  
  36. [input] array.array.string conversations
  37.  
  38. An array of conversations, where each conversation is represented as an array of strings. Each string contains only lowercase English letters.
  39.  
  40. Guaranteed constraints:
  41. 1 ≤ conversations.length ≤ 104,
  42. 1 ≤ conversations[i].length < 100,
  43. 1 ≤ conversations[i][j].length ≤ 15
  44.  
  45. [input] array.string currentConversation
  46.  
  47. The conversation in progress, which needs to be completed by the chatbot. Each string contains only lowercase English letters.
  48.  
  49. Guaranteed constraints:
  50. 1 ≤ currentConversation.length ≤ 100,
  51. 1 ≤ currentConversation[i].length ≤ 15
  52.  
  53. [output] array.string
  54.  
  55. The completed currentConversation.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement