cswork / OA打开练习工作台

AmazonOA #14

Find Similarities (Password Subsequence)

估计中等可在线判题

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

You are given a new password and an old password. Each character of the new password can stay unchanged or be cyclically incremented at most once (z becomes a). Decide whether the old password can become a subsequence of the transformed new password. On this site each test inputs one pair of passwords.

输入格式

The first line contains the new password and the second line the old password; both consist of lowercase English letters, 1≤(old password length)≤(new password length), and the total length of the two strings is ≤200000.

输出格式

Output YES or NO.

样例 1

输入:

baacbab
abdbc

输出:

YES

样例 2

输入:

accdb
ach

输出:

NO

样例 3

输入:

z
a

输出:

YES

样例说明

Example 1: take indices 2, 3, 4, 5, 7 (1-indexed) of the original string to get a, a, c, b, b; after incrementing positions 3, 4 and 7 of the original string once each, the chosen characters become a, b, d, b, c, which is the target abdbc, so output YES. Example 2: no character of the original string can stay as or be incremented to h, so output NO. Example 3: z can be cyclically incremented to a, so output YES.