I think this is one of the most frequently asked interview questions, but I cannot solve it effectively (effective value means less time complexity and using an appropriate data structure). The problem is this: If there are m x n matrixcharacters (say, hay) and a given string of charlength k (needle). Write a program to check if the haystack contains a needle. Please note that we need to search for a haystack only from top to bottom or from left to right. for instance
Haystack
ahydsfd
sdflddl
dfdfd
dfdl
uifddffdhc
Needle:
hdffi
Output:
Yes Found!!
source
share