Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

SOLVE THIS ONE !!!!!! Hello, would someone please help me solve this in vanilla javascript with detailed instructions on how you solved the coding problem.

SOLVE THIS ONE !!!!!! Hello, would someone please help me solve this in vanilla javascript with detailed instructions on how you solved the coding problem.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Please Answer in vanilla javascript. I could not understand this explanation below.

ef solve(wordlist, keypads): solution=[] for keypad in keypads: hashmap = {'A':0, 'B':0, 'C':0, 'D':0, 'E':0, 'F':0, 'G':0, 'H':0, 'I':0, 'J':0, 'K':0, 'L':0, 'M':0, 'N':0, 'O':0, 'P':0, 'Q':0, 'R':0, 'S':0, 'T':0, 'U':0, 'V':0, 'W':0, 'X':0, 'Y':0, 'Z':0 } ans= 0 for letter in keypad: hashmap[letter]+=1 for word in wordlist: for i in range(len(word)): if hashmap[word[i]] == 0: break elif (i==len(word)-1) and (hashmap[word[i]]!= 0): ans+=1 solution.append(ans) return solution

wordlist= ['APPLE', 'PLEAS', 'PLEASE'] keypads = ['AELWXYZ','AELPXYZ','AELPSXY','SAELPRT','XAEBSKY']

print(solve(wordlist,keypads)) For each keypad initialize a empty dictionary containing all upper letters with 0 value.

Now for each of the letter in keypad increment the value in hashmap.

Now loops through all the words and for each letter of each word check whether its value is 0 or not in hashmap.

If this value is not zero means we can continue chrck for other letter and when the last character is matched we are sure that this word can be make from the keypad, perform similar operation for others words also.

In case the value of word in hashmap is 0 then break and check for other words.

at the end we will get the desired solution

1. Escape Room Keypads Problem Statement You're attempting to solve a puzzle in an Escape Room with your team where you need to open a door to get to the next stage. There are several doors, each with a different keypad on it. The keypads each have 7 keys, containing 7 distinct letters. Each keypad looks like this: Enter a word A ELIPS X Y Enter The instructions state that one of the keypads will open the correct door leading to the next stage of the game. Your job is to find a word that unlocks the correct keypad. After struggling for some time, the Escape Room leader gave you a clue, that the first letter of the keypad is guaranteed to be in the word that opens the door. We will call this letter the key" letter. The goal of this exercise is to come up with as many words as possible that your team can test out on the keypads and find the correct combination to go the next stage of the game. What you know: The correct combination will be a valid English word. The words are at least 5 letters long, with no maximum length. The "key" letter will be in the correct answer. The words do not contain any letters outside the seven letters on the keypad. Letters may be reused, including the key" letter. For our purposes, we'll express each set of keypad letters as a string of length 7, where the first letter (the one at position () is the key letter. Requirements Implement a function numKeypad Solutions (wordlist, keypads) that follows the function signature below: Input: wordlist: An array of strings. This is your list of "valid English words for the purposes of the following puzzles. keypads: An array of strings. Each string is the sequence of letters on the keypad. Output: An array of integers. Each integer should be the number of valid words in the corresponding lock. Constraints: Both the wordlist and the keypad letters will be supplied in all capital letters. All words in the wordlist will be of length 5 or greater. Every sequence of keypad letters will be of exactly length 7. Every sequence of keypad letters will consist of 7 distinct letters. Performance of your solution is important! A naive solution will not get you full points - to score 100/100, you'll need something significantly faster. Example Example Input: wordlist: ['APPLE', 'PLEAS', 'PLEASE'] keypads: ['AELWXYZ', 'AELPXYZ', 'AELPSXY', 'SAELPRT', 'XAEBKSY'] Expected output: [0, 1, 3, 2, 0] Explanation: None of the words in the wordlist can be formed from the letters in keypad 0. Only APPLE is valid for keypad 1. APPLE, PLEAS and PLEASE are valid for keypad 2. . Only PLEAS and PLEASE are valid for keypad 3, since APPLE does not contain the key letter S. None of the words are valid for keypad 4, since none contain the key letter X. Here are a few combinations from the example above: PLEASE PLEASE PLEASE OBCPE DO TE DOBBER 7TH BABBERT Bella APPLE / Valld APPLE Xlora APPLE AROPORT DE COOLPRE ABBEST Ek Test Cases Your solution will be run against 10 test cases, each worth 10 points, for 100 points total. The first two test cases are small sample cases, so that you can verify your solution is working. For the sake of example, the first two cases use a small wordlist; however, note that all of the remaining test cases use a modified version of the official Scrabble wordlist, SOWPODS. This wordlist has roughly 260,000 entries. (All entries of less than five letters have been removed). The remaining test cases run against an increasing number of randomly-generated puzzles, and so increasingly test the performance of your solution, as follows: Two test cases run against 5 puzzles. Two test cases run against 200 puzzles. Two test cases run against 1,000 puzzles. Two test cases run against 10,000 puzzles. 1. Escape Room Keypads Problem Statement You're attempting to solve a puzzle in an Escape Room with your team where you need to open a door to get to the next stage. There are several doors, each with a different keypad on it. The keypads each have 7 keys, containing 7 distinct letters. Each keypad looks like this: Enter a word A ELIPS X Y Enter The instructions state that one of the keypads will open the correct door leading to the next stage of the game. Your job is to find a word that unlocks the correct keypad. After struggling for some time, the Escape Room leader gave you a clue, that the first letter of the keypad is guaranteed to be in the word that opens the door. We will call this letter the key" letter. The goal of this exercise is to come up with as many words as possible that your team can test out on the keypads and find the correct combination to go the next stage of the game. What you know: The correct combination will be a valid English word. The words are at least 5 letters long, with no maximum length. The "key" letter will be in the correct answer. The words do not contain any letters outside the seven letters on the keypad. Letters may be reused, including the key" letter. For our purposes, we'll express each set of keypad letters as a string of length 7, where the first letter (the one at position () is the key letter. Requirements Implement a function numKeypad Solutions (wordlist, keypads) that follows the function signature below: Input: wordlist: An array of strings. This is your list of "valid English words for the purposes of the following puzzles. keypads: An array of strings. Each string is the sequence of letters on the keypad. Output: An array of integers. Each integer should be the number of valid words in the corresponding lock. Constraints: Both the wordlist and the keypad letters will be supplied in all capital letters. All words in the wordlist will be of length 5 or greater. Every sequence of keypad letters will be of exactly length 7. Every sequence of keypad letters will consist of 7 distinct letters. Performance of your solution is important! A naive solution will not get you full points - to score 100/100, you'll need something significantly faster. Example Example Input: wordlist: ['APPLE', 'PLEAS', 'PLEASE'] keypads: ['AELWXYZ', 'AELPXYZ', 'AELPSXY', 'SAELPRT', 'XAEBKSY'] Expected output: [0, 1, 3, 2, 0] Explanation: None of the words in the wordlist can be formed from the letters in keypad 0. Only APPLE is valid for keypad 1. APPLE, PLEAS and PLEASE are valid for keypad 2. . Only PLEAS and PLEASE are valid for keypad 3, since APPLE does not contain the key letter S. None of the words are valid for keypad 4, since none contain the key letter X. Here are a few combinations from the example above: PLEASE PLEASE PLEASE OBCPE DO TE DOBBER 7TH BABBERT Bella APPLE / Valld APPLE Xlora APPLE AROPORT DE COOLPRE ABBEST Ek Test Cases Your solution will be run against 10 test cases, each worth 10 points, for 100 points total. The first two test cases are small sample cases, so that you can verify your solution is working. For the sake of example, the first two cases use a small wordlist; however, note that all of the remaining test cases use a modified version of the official Scrabble wordlist, SOWPODS. This wordlist has roughly 260,000 entries. (All entries of less than five letters have been removed). The remaining test cases run against an increasing number of randomly-generated puzzles, and so increasingly test the performance of your solution, as follows: Two test cases run against 5 puzzles. Two test cases run against 200 puzzles. Two test cases run against 1,000 puzzles. Two test cases run against 10,000 puzzles

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions