Trains the technique from
LeetCode 1255Maximum Score Words Formed by LettersThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
You are holding a rack of letter tiles and looking at a list of words you are allowed to play.
rack lists the tiles you hold, one lowercase letter per entry, and the same letter may appear on several tiles. candidates lists the words on offer; you may play any set of them, each word at most once, and words may be played in any order. Playing a word spends one tile for each letter of that word, and a tile spent on one word cannot be spent again on another, so the words you play must be spelled out of your rack all together.
value has 26 entries: value[0] is the points a played 'a' tile is worth, value[1] the points for 'b', and so on to value[25] for 'z'. The score of a play is the total points of every tile it spends.
Return the highest score you can reach. Playing nothing is allowed and scores 0.
Example 1
Playing "pear" and "plum" together spends the tiles p, e, a, r, p, l, u, m, which is exactly the rack. Those tiles are worth 3 + 1 + 2 + 2 + 3 + 4 + 1 + 5 = 21 points. The word "ripe" needs an i tile and the rack holds none.
Example 2
Playing "abc" and "ad" spends a, b, c and a, d, which the rack covers. The score is 1 + 2 + 3 + 1 + 10 = 17.
Example 3
The only word on offer needs an a tile and the rack holds none, so nothing can be played and the score is 0.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def best_rack_score(candidates: list[str], rack: list[str], value: list[int]) -> int:public int bestRackScore(String[] candidates, char[] rack, int[] value)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.