#234. 首尾子串匹配的最大长度

    ID: 234 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatWarmup-2gesp5字符串递归

首尾子串匹配的最大长度

Largest Substring Length

Background

In a string processing challenge, you are tasked with identifying specific patterns.

Problem Description

Given a string str and a non-empty substring sub, compute recursively the largest substring of str which starts and ends with sub and return its length.

Input Format

Input is given from standard input in the following format.

str " " sub

Output Format

Output is printed to standard output in the following format.

length

Sample

catcowcat" "cat
9
catcowcat" "cow
3
cccatcowcatxx" "cat
9

Sample Explanation

For the first sample, the string is "catcowcat" and the substring is "cat". The largest substring that starts and ends with "cat" is "catcowcat" itself, which has a length of 9. For the second sample, the string is "catcowcat" and the substring is "cow". The largest substring that starts and ends with "cow" is "cow\