use DP in longestCommonSubstring

Used the dynamic programming approach to reduce the complexity of longestCommonSubstring to O(mn) from O(mn^2).
@vkostyukov That comes out pretty well using the `Map[(Int,Int),Int]` and `List[Int]`.