1161. Longest Common Substring

EasyDynamic ProgrammingSequence DP

Given two strings a and b, return the length of their longest common substring — the longest run of characters appearing contiguously in both. The input is JSON {a, b}.

Input: JSON {a, b}.

Output: Integer — the length of the longest common substring.

Examples

Example 1
Input: {"a":"ABCDGH","b":"ACDGHR"}
Output: 4
Explanation: 'CDGH' is common.
Example 2
Input: {"a":"abc","b":"abc"}
Output: 3
Explanation: Whole string.
Example 3
Input: {"a":"a","b":"b"}
Output: 0
Explanation: No match.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →