Amazon Online Assessment 2021 (OA) - Decode String Frequency

Amazon Web Services (AWS) is working on a new security feature to help encode text. Consider a string that consists of lowercase English alphabetic letters (i.e., [a-z]) only. The following rules are used to encode all of its characters into string s:

  • a is encoded as 1, b is encoded as 2, c is encoded as 3, ..., and i is encoded as 9.
  • j is encoded as 10#, k is encoded as 11#, l is encoded as 12#, ..., and z is encoded as 26#.
  • If there are two or more consecutive occurrences of any character, then the character count is written within parentheses (i.e., (c), where c is an integer denoting the count of consecutive occurrences being encoded) immediately following the encoded character. For example, consider the following string encodings:
    • String "abzx" encoded as s = "1226#24#".
    • String "aabccc" is encoded as s = "1(2)23(3)".
    • String "bajj" is encoded as s = "2110#(2)".
    • String "wwxyzwww" is encoded as s = "23#(2)24#25#26#23#(3)".

Given an encoded string s, determine the character counts for each letter of the original, decoded string. Return an integer array of length 26 where index 0 contains the number of 'a' characters, index 1 contains the number of 'b' characters and so on.

Relevant Amazon OA Problems:

Input

  • s: an encoded string

Output

an array of 26 integers as described

Examples

Example 1:

Input:

1s = 1226#24#

Output: ``

Explanation:

String "abzx" encoded as s = "1226#24#".

Constraints

  • String s consists of decimal integers from 0 to 9, #, and ()s only.
  • 1<=length of s<=10^5.
  • It is guaranteed that string s is a valid encoded string.
  • 2<=c<=10^4, where c is a parenthetical count of consecutive occurrences of an encoded character.

Try it yourself

Solution

Title

Script

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

Contrary to popular belief, Lorem Ipsum is not simply random text.

1  >>> a = [1, 2, 3]
2  >>> a[-1]
3  3

Get premium for instant access to all content and solutions

Upgrade