Alice and Strings
Practice
3.4 (62 votes)
Algorithms
Easy
String manipulation
Problem
90% Success 17792 Attempts 10 Points 1s Time Limit 256MB Memory 1024 KB Max Code
Two strings \(A\) and \(B\) comprising of lower case English letters are compatible if they are equal or can be made equal by following this step any number of times:
- Select a prefix from the string \(A\) (possibly empty), and increase the alphabetical value of all the characters in the prefix by the same valid amount. For example if the string is \(xyz\) and we select the prefix \(xy\) then we can convert it to \(yz\) by increasing the alphabetical value by 1. But if we select the prefix \(xyz\) then we cannot increase the alphabetical value.
Your task is to determine if given strings \(A\) and \(B\) are compatible.
Input format
First line: String \(A\)
Next line: String \(B\)
Output format
For each test case, print \(YES\) if string \(A\) can be converted to string \(B\) , otherwise print \(NO\).
Constraints
\(1 \le len(A) \le 1000000\\ 1 \le len(B) \le 1000000\)
Submissions
Please login to view your submissions
Similar Problems
Points:10
83 votes
Tags:
Ad-HocApprovedData StructuresEasyImplementationOpen
Editorial