Maximum Score Words Formed by Letters

HardArrayBacktracking

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:7
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:53
Explanation:

Try all 2^4=16 subsets. Best combo uses available letters without exceeding counts, scoring 35.

Constraints

  • 1 ≤ words.length ≤ 14

Ready to solve this problem?

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