Suppose I have a string "abcdpqrs", now "dcb" can be counted as a substring of above string as the characters are together. Also "pdq" is a part of above string. But "bcpq" is not. I hope you got what I want. Is there any efficient way to do this. All I can think is taking help of hash to do this. But it is taking long time even in O(n) program as backtracking is required in many cases. Any help will be appreciated.Suppose I have a string "abcdpqrs", now "dcb" c