cswork / OA打开练习工作台

SalesforceOA #25

Longest Subsequence which is a Substring

估计中等可在线判题

考点(AI 标注)字符串动规双指针滑窗

Find a string that is a subsequence of X and also a contiguous substring of Y, and return its maximum length. Characters of X may be skipped, but characters of Y may not; when there is no common character, output 0.

输入格式

The input is a JSON array [X,Y]. The original gives no numeric or character domain; this site adds that each string has 0..1000 Unicode scalar values, and empty strings, whitespace, control characters, and non-BMP characters are allowed; lone surrogates are not included. The total UTF-8-encoded JSON input is ≤25000 bytes.

输出格式

Output one integer answer.

样例 1

输入:

["abcd","abdc"]

输出:

3

样例 2

输入:

["hackerranks","hackers"]

输出:

7

样例 3

输入:

["","abc"]

输出:

0

样例说明

The outputs of the three public examples are, in order: 3; 7; 0. They have been checked by independent enumeration or direct simulation.