Given a list of words and list of letters. Words can be formed by using letters given and each letter can only be used once.Find maximum no of letters that can be used from the given list to form the words from the word list.
For example
(1) words=[‘dog’,‘og’,‘cat’]
letters=[‘o’,‘g’,‘d’]
Output: “dog’”
Explanation: Using the given letters we can form [“dog”] and [“og”] but output the longer word
(2) words=[“dog”,“do”,“go”]
letters=[“d”,“o”,“g”,“o”]
Output: “do”,“go”
Explanation: Here we can either form [“dog”] or [“do”,“go”] but pick the one which requires more leters.
Was asked to solve in O(n). But could not come up with the required solution. Any leads on how to solve this?