Minimize the trie nodes needed after permuting each string's characters.
Unlock detailed company stats for this questionUpgrade
You are given an array of N strings words. Construct a prefix tree (trie) to store all N strings. Before inserting, you may independently permute the characters of each string in any order. Find the minimum total number of nodes (including the root) needed to represent all N strings after choosing optimal orderings.
Constraints:
- 1 <= N <= 16
- 1 <= length of words[i] <= 10^5
- All strings consist of lowercase English letters.
Example: Input: N = 3, words = ["pqr", "qps", "ptr"] Output: 7 Explanation: permute the words to ["pqr", "pqs", "ptr"]. Root: 1 node; shared prefix 'p': 1 node; shared prefix 'pq' between words 1 and 2: 1 node; unique suffix nodes ('r', 's' and 'tr'): 4 nodes. Total = 7.
Community answers
No answers contributed by the community yet.
Related questions
Sort the characters in a string.Find the minimum characters to insert to make a string a palindrome.Related courses

Course

Course
Course
