use DP in longestCommonSubstring

Used the dynamic programming approach to reduce the complexity of longestCommonSubstring to O(mn) from O(mn^2).
We still use array here. Can we use `List` instead? But we have to avoid random access with list.