FastPrepFastPrep
Problem Brief

Calculate String Transformations Length

INTERNOA

For a string word of length n consisting of lowercase English characters, it can be transformed as follows.

  • For each character of the string:

    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).

    1Example 1

    Input
    word = "abczy", t = 2
    Output
    TO-DO
    Explanation

    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
    Resulting string: "bcdabz"

    In the 2nd transformation:

    • b → c
    • c → d
    • d → e
    • a → b
    • b → c
    Resulting string: "cdedbc"

    public int calculateTransformationsLength(String word, int t) {
      // write your code here
    }
    
    Input

    word

    "abczy"

    t

    2

    Output

    TO-DO

    Sign in to submit your solution.