use DP in longestCommonSubstring

Used the dynamic programming approach to reduce the complexity of longestCommonSubstring to O(mn) from O(mn^2).
Using `return` here is unnecessary. You can do just if (i > a.length) loop(...)`. Also other places are not required return. Using the `return` explicitly is not really a Scala style.