I tried the crossword problem in backtracking and recursion section. I am not able to pass the last two test cases. Any help is appreciated.
Problem Description:
CROSSWORD
You are given a dictionary consisting of N words each containing lowercase letters ‘a’-‘z’. You also have MxM crossword consisting of lowercase letters ‘a’-‘z’. You want to print all possible words that can be formed by a sequence of adjacent characters. Note that you can move to any of 8 adjacent characters, but a word should not have multiple instances of same cell. Note :- if a word is present in crossword more than once print it once.
Input Format:
First line contains integer N. Then follow N space seperated words. Next line contains integer M. Then you have M characters each in next M lines forming MxM grid.
Constraints:
1 <= N <= 10 1 <= M <= 5
Output Format
Print all words of dictionary present in crossword with space between words.
Code Link: click here
Edit:
Small mistake in dfs function.Now i got AC