Maximum Score Words Formed by Letters

Hard

Description

Given words, letter pool, and letter scores, return the maximum score achievable by forming any combination of valid words using available letters.

Examples

Input:words = ["dog","cat","dad","good"], letters = ["a","a","c","d","d","d","g","o","o"], score = [1,0,9,5,0,0,3,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0]
Output:23
Explanation:

Max score forming dad and good.

Input:words = ["dog","cat","dad","good"], letters = ["a","a","c","d","d","d","g","o","o"], score = [1]
Output:1
Explanation:

Edge case with a single-element array.

Input:words = ["hello","world","code","love"], letters = ["c","d","e","e","h","l","l","o","o","r","v","w"], score = [0,0,4,2,3,0,0,1,0,0,0,6,0,0,7,0,0,5,0,0,0,8,9,0,0,0]
Output:35
Explanation:

The optimal word combination using available letters yields a maximum score of 35.

Constraints

  • 1 ≤ words.length ≤ 14

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!