Amazon Interview Question
Country: India
Please elaborate on this. This will work only if the strings are the same position from the starting and ending point. As in if "name" is the second word from the beginning the "eman" needs to be the second word from the end.
According to the requirement "Given a file which contains large number of strings." , I dont think this order is preserved. So how will you know that the string has appeared twice ?
Or are you suggesting that for every one word forward traverse the whole file backwards ?
@Nascent, Yes Please elaborate "don’t compute reverse of string at all" ?
Regarding first part, hashing of words should be one solution.
We can search strings forward and backward in the file. If we find a string at both direction we can log the string.
- Ali Katkar October 12, 2014