Two strings and 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 (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 and we select the prefix then we can convert it to by increasing the alphabetical value by 1. But if we select the prefix then we cannot increase the alphabetical value.
Your task is to determine if given strings and are compatible.
Implementation of above approach with Code
- First try to find length of strings .If lengths are not equal then it is not possible to convert A to B
- Secondly,Find no of conversions required for prefix if the no of conversions of prefix is less than the remaining part of string,then also it is not possible to convert A to B.
using namespace std;
//If lengths are not equal obviously A cant be converted to B
//No of conversions required for the prefix should be greater
//If no of conversions required for prefix is less then it is not possible to convert