Two Approaches in c++ explained well 🔥
FIRST APPROACHIntuitionBy using map or freq array to store the counts of each character present in our string.Note: Using freq array instead of map is good appr
# FIRST APPROACH


# Intuition
By using map or freq array to store the counts of each character present in our string.

Note: Using freq array instead of map is good approach as creating again and again map for each transformation will give TLE.
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach:
1. Start
2. Make a freq array or a map to store the count of each character present in our string.
3. For each transformation by using while loop.
4. We will make a new freq array which stores the updated count of each character present in our array after transformation. Like if it is 'z' then it will be increment the count of 'a' and 'b' both else it will only increment the count of next character. Update the freq array with new freq array which was just created after each iteration.
5. In the end, we will add the frequency of each character present in our array to the ans.
6. Return the ans.
7. End.
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity: O(t)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(26)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# SECOND APPROACH
# Intuition
Precomputation helps a lot in this case like this way: after this much transformations how many characters will be incremented like that.
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach:
1. Start
2. Make an array of storing incremented characters after transformation like maximum transformation allowed is 10^5 so we will make an array of storing incrementations till 100026 characters.
3. For first transformation i.e. from 0 to 26 we will be having only 1 increment so we will initialize it by 1 .
4. After that from 26 to 100026 we will be having increment by using this formula: afterTransformation[i-25]+afterTransformation[i-26].
5. Like this we initialize our array.
6. Now, iterate through the string.
7. Adding values of transformations from the array after t transformations for that particular character to the ans variable with calculating mod also.
8. Return the ans.
9. End.
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity: O(10^5+n) => O(10^5)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(10^5)
# <!-- Add your space complexity here, e.g. $$O(n)$$ -->

*First approach is best. But if the number of transformations is less like lessthan the given constraints i.e. 10^5. Second approach is also best.
For constraints 10^5 , both approaches work well. Neither of them will give you TLE but make sure you are using freq array not map in second approach.*

# Code
```cpp []
class Solution {
public:
    int lengthAfterTransformations(string s, int t) {
        //first approach
        vector<long long>freq(26,0);
        int mod = 1e9+7;
        for(char c:s){
            freq[c-'a']++;
        }

        while(t--){
            vector<long long>freq1(26,0);
            for(int i=0;i<26;i++){
                if(freq[i]>0){
                    if(i==25){
                        freq1[0]+=(freq[i]%mod);
                        freq1[1]+=(freq[i]%mod);
                    }
                    else{
                        freq1[i+1]+=(freq[i]%mod);
                    }
                }
            }
            freq=freq1;
        }

        long long ans=0;
        for(int i=0;i<26;i++){
            ans+=(freq[i]%mod);
        }

        return ans%mod;
        //second approach
        // int afterTransformation[100026];
        // int mod = 1e9+7;
        
        // //for first transformation we will be having increment of 1 character that means a to b , b to c
        // for(int i=0;i<26;i++){
        //     afterTransformation[i]=1;
        // }
        // //for second , third and so on transformation we will see increment of two character like a 2 times to b 2times like this
        // for(int i=26;i<100026;i++){
        //     afterTransformation[i]=(afterTransformation[i-25]+afterTransformation[i-26])%mod;
        // }

        // long long ans=0;
        // for(char c:s){
        //     ans = (ans+afterTransformation[c-'a'+t])%mod;
        // }

        // return ans;

    }
};
```
['Hash Table', 'Math', 'String', 'Dynamic Programming', 'Counting', 'C++']