title: Using Scala how to find out if a list of chars are present in a String, where there are duplicate characters?
body: <p>Consider the following example , I have a given set of <strong>words</strong> and a given set of <strong>chars</strong> . I have to find out if there is a word which can be made from the list of chars while respecting duplication - i.e. the word is a multiset subset of the multiset of chars. Thus for chars <code>List('a', 'p', 'q', 'r', 's')</code>, word <code>"apqsrr"</code> is not a valid solution since it contains two <code>'r'</code>s. The usual solution that I can think of is to iterate over chars of a word and if a match is found in chars then remove that char from chars list. This can handle duplicates but I don't know how to write this in scala in a more <strong>functional way</strong>.</p>
  
  <p>From what knowledge I have of scala I was able to write the following code, which works fine if there are no duplicate letters.</p>
  
  <pre><code>val words = List("apqsrr", "avadavat", "avail", "availability", "available", 
    "avalanche", "avantgarde", "avarice")
  val chars = List('a', 'p', 'q', 'r', 's')
  
  for (w &lt;- words if w.forall(chars.contains)) yield w
  
  // another way 
  words.find(_.forall(chars.contains))
  </code></pre>