VOOZH about

URL: https://www.geeksforgeeks.org/dsa/print-valid-words-possible-using-characters-array/

⇱ Print all valid words that are possible using Characters of Array - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Print all valid words that are possible using Characters of Array

Last Updated : 23 May, 2026

Given a dictionary and a character array, print all valid words that are possible using characters from the array. 

Examples: 

Input : Dict - {"go","bat","me","eat","goal", "boy", "run"}
arr[] = {'e','o','b', 'a','m','g', 'l'}
Output : go, me, goal.

Asked In : Microsoft Interview

The idea is to use Trie data structure to store dictionary, then search words in Trie using characters of given array. 

  1. Create an empty Trie and insert all words of given dictionary into the Trie.
  2. After that, we have pick only those characters in β€˜Arr[]’ which are a child of the root of Trie.
  3. To quickly find whether a character is present in array or not, we create a hash of character arrays.

Below is the implementation of above idea 


Output
go
goal
me

Time Complexity: O(SIZE^L * N) where L is the length of the longest word in the dictionary and N is the length of the input array. 
Auxiliary Space: O(SIZE^L)

Comment
Article Tags: