For this Question: Given a dictionary, a method to do lookup in dictionary and a M x N board where every cell has one character. Find all possible words that can be formed by a sequence of adjacent characters. Note that we can move to any of 8 adjacent characters, but a word should not have multiple instances of same cell.

Example:

Input: dictionary[] = {"GEEKS", "FOR", "QUIZ", "GO"};
       boggle[][]   = {{'G','I','Z'}, {'U','E','K'}, {'Q','S','E'}};

Output:  Following words of the dictionary are present
         GEEKS, QUIZFirst line contains an integer X denoting the no of words in the dictionary. Then in the next line are X space separated strings denoting the contents of the dictionary. In the next line are two integers N and M denoting the size of the boggle. Next N lines each contains M characters denoting the contents of the boggle.

Constraints:
1 < = X < = 10
1 < = N, M < = 4
1 < = |String| < = 10
All input strings are made up of uppercase characters of the English alphabets.Print in a single line and in a sorted order all the words of the dictionary which could be formed from the boggle. If no word can be formed print -1.Sample Input:
4
GEEKS FOR QUIZ GO
3 3
G I Z 
U E K 
Q S E

Sample Output:
GEEKS QUIZ, I have written this Solution Code: import java.io.*;
import java.util.*;



class Main {
	public static void main (String[] args) throws IOException {
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	   int n = Integer.parseInt(br.readLine());
	   String str1 = br.readLine();
	   String[] str2 = str1.split(" ");
	   String str3 = br.readLine();
	   String[] str4 = str3.split(" ");
	   int row = Integer.parseInt(str4[0]);
	   int col = Integer.parseInt(str4[1]);
	   char[][] cha = new char[row][col];
	   for(int i = 0; i < row; ++i) {
		  String str5 = br.readLine();
		  String[] str6 = str5.split(" ");

		   for(int j = 0; j < col; ++j) {
			   cha[i][j] = str6[j].charAt(0);

		   }
	   }
	   List<String> list = new ArrayList<>();
	   for(int i = 0; i < n; ++i) {
		   if(solve(cha,str2[i])) {
			   list.add(str2[i]);
		   }
	   }
	   if(list.size() == 0) {
		   System.out.print(-1);
	   } else {
		   Collections.sort(list);
		   for(String i : list) System.out.print(i+" ");
	   }
	}
	static boolean solve(char[][] arr,String str) {


		for(int i = 0; i < arr.length; ++i) {
			for(int j = 0; j < arr[0].length; ++j) {
				if(helper(arr, str, i, j, 0)) {
					return true;
				}
			}
		}
		return false;
	}
	static boolean helper(char[][] arr, String str, int i, int j, int index) {
		if(index >= str.length()) return true;
		if(i < 0 || j < 0 || i > arr.length-1 || j > arr[0].length-1 || arr[i][j] != str.charAt(index)) {
			return false;
		}
		char temp = arr[i][j];
		arr[i][j] = '#';
		if(helper(arr, str, i-1, j, index+1) || helper(arr, str, i-1, j+1, index+1) ||
		helper(arr, str, i, j+1, index+1) || helper(arr, str, i+1,j+1, index+1) || helper(arr,str,i+1,j,index+1) ||
		helper (arr, str, i+1, j-1, index+1) || helper(arr, str, i, j-1, index+1) ||
		helper(arr, str, i-1, j-1, index+1)) {
			arr[i][j] = temp;
			return true;
		}
		arr[i][j] = temp;
		return false;
	}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?