Spelling bee judge
EasyOnline Assessment
Judge the attempts of a school spelling bee against the word that was given.
Every contestant spelled the same word. Compare each attempt with word letter by letter, ignoring upper/lower case, and give one verdict per attempt:
- If the attempt does not have exactly the same number of letters as
word, the verdict is"OUT". - Otherwise count the slips: the positions where the attempt's letter differs from the word's letter.
- No slips:
"PERFECT". - At least one slip, at most
slipsslips in total, and no two slips in neighbouring positions:"PASS"(the judges forgive scattered mistakes, but not stumbling over two letters in a row). - Anything else:
"OUT".
Input: word, a string; attempts, a list of strings; slips, the number of slips the judges forgive.
Output: a list of verdict strings, one per attempt, in the same order. If there are no attempts, return [].
Example 1
- Input:
- ["Necessary",["necessary","NECESARY","Neccesary","necessery"],2]
- Output:
- ["PERFECT","OUT","OUT","PASS"]
- Explanation
necessarymatches the word exactly apart from capital letters, so it is PERFECT.NECESARYhas 8 letters instead of 9, which is OUT whatever its letters are.Neccesaryhas two wrong letters (positions 3 and 4) and the budget is 2, but they sit next to each other, so the judge does not forgive it: OUT.necesseryhas a single wrong letter,ewhereabelongs: PASS.
Example 2
- Input:
- ["rhythm",["rhytmh","rhythm","rhuthn","Rhythm"],2]
- Output:
- ["OUT","PERFECT","PASS","PERFECT"]
- Explanation
rhytmhhas two wrong letters in positions 4 and 5, adjacent, so it is OUT.rhythmandRhythmare PERFECT (case is ignored).rhuthnhas wrong letters at positions 2 and 5, which are not adjacent and fit the budget of 2: PASS.
Example 3
- Input:
- ["banana",["banano","bonono","","BANANA"],1]
- Output:
- ["PASS","OUT","OUT","PERFECT"]
- Explanation
- The budget is 1.
bananohas one wrong letter: PASS.bononohas three wrong letters, over budget: OUT. The empty attempt has the wrong length: OUT.BANANAis PERFECT.
Constraints
1 <= word.length <= 200 <= attempts.length <= 30, and0 <= attempts[i].length <= 250 <= slips <= 5wordand every attempt contain only English letters