educative.io

Re: Longest Common Substring

For Longest Common Substring, it would make sense to explicitly state that the String.contains() method cannot be used - because that’s not obvious and there is a non-trivial solution that utilizes the String.contains() method as well, re:

" Problem statement

Given two strings, s1 and s2, write a function that finds and returns the length of the longest substring of s2 and s1 (if any exist)."


Course: https://www.educative.io/collection/10370001/5347133077061632
Lesson: https://www.educative.io/collection/page/10370001/5347133077061632/4993289797238784


Course: https://www.educative.io/collection/10370001/5347133077061632
Lesson: https://www.educative.io/collection/page/10370001/5347133077061632/4993289797238784

Hi @Nilay_Jhaveri !!
You’re absolutely right; it’s essential to clarify that the String.contains() method cannot be used in the context of finding the longest common substring between two strings. The Solution is implementing a dynamic programming approach to solve this problem, which is a standard and efficient way to do so.
We will add note [ Note: The solution should not utilize the String.contains() method, as this method may not be suitable for finding the longest common substring in a non-trivial way.] after the problem statement in the lesson and let you know once it’s updated.
Thanks
Happy Learning :blush:

Re: “method, as this method may not be suitable for finding the longest common substring in a non-trivial way.]”, that’s not what I meant, I meant that there is a non-trivial solution for finding LCS which uses string.contains, that’s why I was pointing out that it’s best to clarify that it shouldn’t be used if it’s not intended to be used.

1 Like

Thank you for the clarification. To address your concern, it’s indeed important to clarify that while there are different ways to find the longest common substring, the intention of the provided code is to implement a non-trivial solution using dynamic programming. Therefore, it’s best to explicitly mention that using the String.contains() method is not the intended approach for solving the problem in this specific context.