Count how many characters remain after repeatedly transforming a string under fixed replacement rules.
You are given a string and a transformation rule that is applied repeatedly for a fixed number of rounds. In each round, every character is replaced according to the rule, which changes the string length over time. Your task is to determine the total number of characters after all rounds of transformation.
Because the string can grow very quickly, focus on counting the length rather than constructing the full transformed string whenever possible.
Return the total number of characters present after applying the transformation exactly times.
Example 1
Input
s = "a", k = 1
Output
2
Explanation
After one transformation, the single character expands according to the rule, so the total length becomes 2.
Example 2
Input
s = "ab", k = 2
Output
4
Explanation
Apply the transformation twice and count the resulting characters instead of writing the entire final string.
Premium problem context
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.