Solved LeetCode program · 908 of 1,000
#1255 · Maximum Score Words Formed by Letters
Original English source
Keep a shared needed as a list of 26 zeros. Keep a shared available holding 2, 0, 1, 3, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, and 0. Keep a shared wordcounts holding 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, and 0. Keep a shared wordscores holding 8, 10, 11, and 8. Keep a shared weights holding 1, 2, 4, and 8. Keep a shared total of 0. Keep a shared best of 0. Keep a shared fit of 1.
To reset from letter (a whole number). If letter is more than 25, return. Set item letter of needed to 0. Reset from letter plus 1.
To addcounts from letter (a whole number) with base (a whole number). If letter is more than 25, return. Increase item letter of needed by item (base plus letter) of wordcounts. Addcounts from letter plus 1 with base.
To include from word (a whole number). The base is word times 26. Addcounts from 0 with base. Increase total by item word of wordscores.
To measure from mask (a whole number) with word (a whole number). If word is more than 3, return. The bit is bitwise and of mask and item word of weights. If bit is not 0, include from word. Measure from mask with word plus 1.
To inspect from letter (a whole number). If letter is more than 25 and fit is 1 and total is more than best, set best to total. If letter is more than 25, return. If item letter of needed is more than item letter of available, set fit to 0. Inspect from letter plus 1.
For every mask from 0 to 15.
Set total to 0. Set fit to 1. Reset from 0. Measure from mask with 0. Inspect from 0.
Show best.
Expected stdout
19