465. Check If Anagram of a Word Can Be Found in Note
Check If Anagram of a Word Can Be Found in Note

Given a list of strings words and a string note, return true if an anagram of any word in words can be found in note, otherwise return false.

The letters of the anagram can be in any order and need not be next to each other in note, but each letter of note can be used at most once.

Method Signature

boolean canFindAnagram(List<String> words, String note)
  • words: candidate words
  • note: string to search in

Constraints

  • 1 ≤ words.size() ≤ 1,000
  • 1 ≤ words.get(i).length() ≤ 100
  • 1 ≤ note.length() ≤ 100,000
  • words.get(i) and note contain only lowercase English letters

Examples

Example 1

Input: canFindAnagram(words = ["cat", "dog", "bird"], note = "golden")

Output: true

Explanation: The letters 'd', 'o' and 'g' of "dog" all occur in "golden".

Example 2

Input: canFindAnagram(words = ["moon", "star"], note = "monday")

Output: false

Explanation: "moon" needs two 'o' but "monday" has only one, and "star" needs an 's', which "monday" lacks.

Example 3

Input: canFindAnagram(words = ["peel"], note = "pebble")

Output: true

Explanation: "peel" needs one 'p', two 'e' and one 'l', and "pebble" has all of them.



Please use Laptop/Desktop or any other large screen to add/edit code.