## LCS - Longest Common Substring

no tags

A string is finite sequence of characters over a non-empty finite set Σ.

In this problem, Σ is the set of lowercase letters.

Substring, also called factor, is a consecutive sequence of characters occurrences at least once in a string.

Now your task is simple, for two given strings, find the length of the longest common substring of them.

Here common substring means a substring of two or more strings.

### Input

The input contains exactly two lines, each line consists of no more than 250000 lowercase letters, representing a string.

### Output

The length of the longest common substring. If such string doesn't exist, print "0" instead.

### Example

```Input:
alsdfkjfjkdsal
fdjskalajfkdsla

Output:
3
```

hide comments
 < Previous 1 2 3 4 5 6 Next > yk_666: 2023-12-25 09:46:17 Suffix Automaton O(n) 0.06s AC pengzijun: 2023-09-27 07:38:43 hash O(nlogn) TLE? sleepntsheep: 2023-08-27 15:36:29 O(nlogn) suffix array TLE, too strict time limit? cubyte: 2022-11-23 07:42:29 A good problem for practicing suffix array. My O(n log n) solution got TLE.How can I optimize my solution? Update:Now it gets WA... Update:Now it passed!My radix sort was wrong XD Last edit: 2022-11-23 08:24:10 rafi22: 2022-05-27 13:26:45 TLE TLE TLE TLE.... bc gaand maar liya is question ne to wonderfulwhale: 2022-05-24 17:49:35 Suffix Automaton O(n) AC 0.27s Last edit: 2022-05-27 13:12:15 tr_abhishek: 2021-05-13 10:18:33 TLE TLE TLE TLE.... bc gaand maar liya is question ne to allenge: 2021-05-08 11:19:16 SuffixAutoMaton O(n) AC 0.04s treenipples: 2021-02-23 13:59:03 Prefix hash O(nlog^2n) with vector + sorting passed in 0.77s Last edit: 2021-03-03 23:46:40 sharath1999: 2020-08-04 15:51:03 Suffix automaton worked super quick for me

 Added by: Bin Jin Date: 2007-09-24 Time limit: 1s Source limit: 50000B Memory limit: 1536MB Cluster: Cube (Intel G860) Languages: All except: ASM64 CPP