Skip to main content
Back to problems
Leetcode
Medium
Arrays
Strings
Math
Dynamic Programming
Total Characters in String After Transformations II

Compute the total length of a string after repeatedly applying a character transformation rule for a fixed number of rounds.

Acceptance 100%
Problem Statement

Problem

You are given a string ss consisting of lowercase English letters and an integer tt.

In one transformation round, every character in the string is replaced according to a fixed rule. The exact replacement rule depends on the character, but the important property is that each round can increase the total number of characters.

Your task is to determine the total number of characters in the string after applying the transformation exactly tt times.

Because the answer can become very large, return it modulo 109+710^9 + 7.

Goal

Design an efficient algorithm that avoids explicitly constructing the transformed string when tt is large.

Input Format

  • A string s.
  • An integer t representing the number of transformation rounds.

The exact per-character replacement rule is assumed to be provided by the problem’s transformation specification.

Output Format

  • Return a single integer: the length of the string after exactly t transformations, modulo 109+710^9 + 7.

Constraints

  • 1s1051 \le |s| \le 10^5
  • 0t1090 \le t \le 10^9
  • The transformed string length may grow exponentially.
  • Use modulo 109+710^9 + 7 in the final answer.
Examples
Sample cases returned by the problem API.

Example 1

Input

s = "ab"
t = 2

Output

4

Explanation

After applying the transformation rule twice, the string contains 4 characters in total.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.