cswork / OAOpen practice workspace

AmazonOA #14

Find Similarities (Password Subsequence)

Estimated MediumJudge-ready

Topics (AI-labelled)Two PointersStrings

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.

Input

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

Output YES or NO.

Example 1

Input:

baacbab
abdbc

Output:

YES

Example 2

Input:

accdb
ach

Output:

NO

Example 3

Input:

z
a

Output:

YES

Example notes

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.

Editorial

Loading solution…