This is the dynamic programming solution for longest common substring.

Please refer to this page - http://en.wikipedia.org/wiki/Longest_common_substring_problem#Pseudocode

This explains why it should be hash[i-1][j-1] + 1