
You are given a string encoded with a special algorithm. Your task is to decode the string and count the frequency of each letter from 'A' to 'Z' in the final decoded message.
The encoding rules are as follows:
Your function should not return the full decoded string (which could be very long). Instead, it must return an array or list of 26 integers, where the element at index 0 is the frequency of 'A', at index 1 is the frequency of 'B', and so on.
The first and only line of input contains the encoded string s.
Your function should return a list/array of 26 integers. The runner code will handle printing these integers separated by spaces.
The key to solving this efficiently is to parse the string without actually constructing the fully decoded string. Iterate through the encoded string, decode one character representation at a time, check for an optional repetition block, and update a frequency array directly.
1[3]12#2[4]
3 4 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1[3]: The digit 1 represents 'A'. It is followed by [3], so the count of 'A' is 3.
12#: The number 12 followed by # represents 'L'. There is no repetition block, so the count of 'L' is 1.
2[4]: The digit 2 represents 'B'. It is followed by [4], so the count of 'B' is 4.
Final Frequencies: 'A': 3, 'B': 4, 'L': 1. The output array shows these counts at their respective positions.
The expected time complexity is O(N).
1 <= length of s <= 2000
1 <= k (in [k]) <= 1000
The input string is guaranteed to be well-formed according to the rules.
Time Limit: 1 sec