Longest Common Substring

Given two nonempty lowercase strings str1 and str2, return the length of their longest shared contiguous substring. Characters in the chosen run must be…

Given two nonempty lowercase strings str1 and str2, return the length of their longest shared contiguous substring. Characters in the chosen run must be adjacent in both strings. Return 0 when there is no common character. Return only the length.

- 1 <= character length of each operand <= 1000. - Only lowercase ASCII letters a through z. - The visualizer accepts each operand up to 8 characters; longer valid inputs are coding-only.

Example 1: input str1 = "starlit", str2 = "starlet"; output 5. starlit and starlet share starl, length 5. Their final t matches too, but that terminal run has length 1; returning only the bottom-right cell would miss the earlier best.

Example 2: input str1 = "pqr", str2 = "stu"; output 0. No valid shared match satisfies the stated ordering and character conditions.

Example 3: input str1 = "a", str2 = "a"; output 1. The stated character and ordering conditions determine this length.

Category: Strings. Topic: dynamic-programming. Difficulty: hard. Patterns: dynamic-programming.