Calculate String Transformations Length
Learn this problemProblem statement
For a string word of length n consisting of lowercase English characters, it can be transformed as follows.
1. If the character is 'z', it is replaced by "ab".
2. Otherwise, it is replaced by its next higher character, for example, 'a' is replaced by 'b', 'b' by 'c' ... and 'y' by 'z'.
Thus, if the initial string is "azbk" it is "babcl" after 1 transformation.
As a fun trivia, HackerRank publishes a puzzle for all its employees each week. The goal for this week is to find the length of the resultant string after exactly t transformations are performed as described above. Since the answer can be large, find the answer taking modulo (109 + 7).
Function
calculateTransformationsLength(word: String, t: int) → intExamples
Example 1
word = "abczy"t = 2return = 7
Consider word = "abczy" and the number of transformations t = 2.
In the 1st transformation, the characters are transformed as follows:
- a → b
- b → c
- c → d
- z → ab
- y → z
In the 2nd transformation:
- b → c
- c → d
- d → e
- a → b
- b → c
- z → ab