Backtracking: Word Puzzle Alice has made a Nx N grid of characters. She has M words with her. A word is said to be prese

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Backtracking: Word Puzzle Alice has made a Nx N grid of characters. She has M words with her. A word is said to be prese

Post by answerhappygod »

Backtracking Word Puzzle Alice Has Made A Nx N Grid Of Characters She Has M Words With Her A Word Is Said To Be Prese 1
Backtracking Word Puzzle Alice Has Made A Nx N Grid Of Characters She Has M Words With Her A Word Is Said To Be Prese 1 (69.44 KiB) Viewed 28 times
Backtracking Word Puzzle Alice Has Made A Nx N Grid Of Characters She Has M Words With Her A Word Is Said To Be Prese 2
Backtracking Word Puzzle Alice Has Made A Nx N Grid Of Characters She Has M Words With Her A Word Is Said To Be Prese 2 (62.51 KiB) Viewed 28 times
Backtracking Word Puzzle Alice Has Made A Nx N Grid Of Characters She Has M Words With Her A Word Is Said To Be Prese 3
Backtracking Word Puzzle Alice Has Made A Nx N Grid Of Characters She Has M Words With Her A Word Is Said To Be Prese 3 (29.66 KiB) Viewed 28 times
Backtracking: Word Puzzle Alice has made a Nx N grid of characters. She has M words with her. A word is said to be present in the grid if it can be formed from a sequence of characters that are either horizontally or vertically or diagonally adjacent. Find the number of words that are present in the grid. Note: For a word, you cannot use a character at a position more than once. Function Description: In the provided code snippet, implement the provided formWords (...) method using the variables to print the number of words that are present in the grid. You can write your code in the space below the phrase "WRITE YOUR LOGIC HERE". There will be multiple test cases running so the Input and Output should match exactly as provided. The base Output variable result is set to a default value of -404 which can be modified. Additionally, you can add or remove these output variables. Input Format The first line of input contains two integers N and M. The next N lines will contain N space-separated lowercase characters stored in a matrix alpha. The next line contains M space-separated strings stored in a string array words. Sample Input
sample input 43 dtth lowercase characters. sgqt characters. zety characters. dvgj characters. as hqe sdtth --denotes N and M. --denotes N space-separated --denotes N space-separated lowercase --denotes N space-separated lowercase --denotes N space-separated lowercase --denotes M space-separated strings. Constraints 1 <= N <= 10, 1 <= M <= 100 1 <= words.length() <= 100 Output Format The output contains a single integer denoting the total number of words that are present in the grid. Sample Output 2 Explanation The first word "as" cannot be formed as "a" is not present in the grid. The second word "hqe" can be formed by sequentially using the characters at positions (0,3), (1,2), and (2,1). The third word "sdtth" can be formed by sequentially using the characters at positions (1,0), (0,0), (0,1), (0,2), and (0,3). Hence, 2 words can be formed using the grid. Or
er of 1 2 3 4 5 6 7 8 9 10. 11 12 13 1 15 16 17 18 19 20 21 22 23 def formWords (N, M, alpha, words): #this is default OUTPUT. You can change it. result = -404 #write your Logic here: return result #INPUT [uncomment & modify if required] temp input().split() Nint (temp [0]) Mint (temp [1]) alpha= [] for i in range (N): alpha.append(input().split()) words = [] temp for i in range (M): input().split() words.append(temp [1]) #OUTPUT [uncomment & modify if required] print (formWords (N, M, alpha, words)).
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply