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
Posted: Fri Jul 08, 2022 6:38 am
sgqt characters. zety characters. dvgj characters. as hqe sdtth --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.
56789 10 11 12 13 12 14 15 PPP 16 17 18 19 20 21 22 23 24 w w w w w w w w w N N N N N N N 25 26 27 28 29 30 31 32 234 in 33 34 35 36 679 37 public class Main{ public static int formWords (int n, int M, String[] [] alpha, String[] words) { //this is default OUTPUT. You can change it. int result = -404; 38 } } //write your Logic here: return result; public static void main (String[] args) { Scanner sc = new Scanner(System.in); // INPUT [uncomment & modify if required] int N = sc.nextInt (); int M = sc.nextInt (); String[] [] alpha = new String [N] [N]; for(int i=0; i<n; i++) { } for(int j = 0; j<N; j++){ alpha [j] =sc.next(); } } String[] words = new String [M]; for (int i = 0; i < M; i++) { T words = sc.next(); } sc.close(); System.out.print(formWords (N, M, alpha, words));