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.
Example:
Input: dictionary[] = {"GEEKS", "FOR", "QUIZ", "GO"}; boggle[][] = {{'G','I','Z'}, {'U','E','K'}, {'Q','S','E'}}; Output: Following words of dictionary are present GEEKS, QUIZ
Below is my code:
dictSize=int(raw_input()) dictionary=raw_input().split(' ') m,n=map(int,raw_input().split(' ')) boggle=[[0 for x in range(n)] for y in range(m)] #print dictionary bString=raw_input().split() for i in range(0,m): for j in range(0,n): boggle[i][j]=bString[(i*n)+j] #print boggle lookUp={} for i in range(0,m): for j in range(0,n): lookUp[boggle[i][j]]=lookUp.get(boggle[i][j],0)+1 possibility=[] flag=0 for i in range(0,len(dictionary)): for s in dictionary[i]: if(lookUp.has_key(s)): flag=0 else: flag=1 if(flag==0): possibility.append(dictionary[i]) #print possibility for i in range(0,len(possibility)): print possibility[i],