/**
 * @Company Facebook
 *
 * Given two strings, str and pattern, return true if the str has a valid mapping between the words in str and the characters in the pattern.
 * The str will be whitespace separated and the pattern will be depicted using characters.
 *
 * Problem Ex.
 *   Input: 'cat dog dog cat', 'abba'
 *   Output: true because cat = a and dog = b.
 *
 *   Input: 'cat dog dog foo', 'abba'
 *   Output: false because cat = a so foo cannot == a
 */
public boolean isValidPattern(String str, String pattern) { }

@@ -458,68 +458,869 @@
 a%0A *
-/%0Apublic boolean isValidPattern(String str, String pattern) %7B %7D%0A
+%0A * Note: use may assume the pattern string will only contain lowercase alphabet letters.%0A */%0Apublic boolean wordPattern(String pattern, String str) %7B%0A  // map each letter to a string.%0A  String%5B%5D strs = str.split(%22%5C%5Cs%22);%0A  // character -%3E string mapping%0A  String%5B%5D map = new String%5B26%5D;%0A  HashSet%3CString%3E set = new HashSet%3CString%3E();%0A%0A  // Must be equal in length.%0A  if (strs.length != pattern.length()) return false;%0A%0A  for (int i = 0; i %3C strs.length; i ++) %7B%0A    String string = strs%5Bi%5D;%0A    char c = pattern.charAt(i);%0A    int index = c - 'a';%0A%0A    // First occurence of the character.%0A    if (map%5Bindex%5D == null && !set.contains(string)) %7B%0A      map%5Bindex%5D = string;%0A      set.add(string);%0A%0A    // Valid pattern match%0A    %7D else if (map%5Bindex%5D != null && map%5Bindex%5D.equals(string)) %7B%0A      continue;%0A    %7D else %7B%0A      return false;%0A    %7D%0A  %7D%0A%0A  return true;%0A%7D

Add bipartite pattern matching solution