PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates proficiency in string parsing and frequency aggregation, specifically handling mixed-length encodings, tokenization of digits and '#' markers, and parsing numeric repetition counts while respecting linear-time and constant-space constraints.

  • medium
  • Oracle
  • Coding & Algorithms
  • Software Engineer

Compute letter frequencies from encoded string

Company: Oracle

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem You are given an encoded string `s` representing a string of lowercase English letters (`a`–`z`). The encoding follows these rules: 1. Letters `a` to `i` are encoded as digits `1` to `9`. - `a -> "1"`, `b -> "2"`, …, `i -> "9"` 2. Letters `j` to `z` are encoded as two digits followed by `#`. - `j -> "10#"`, `k -> "11#"`, …, `z -> "26#"` 3. If a letter repeats **consecutively** `k >= 2` times, the repetition is encoded by appending `"(k)"` immediately after that letter’s code. - Example: `"aa" -> "1(2)"`, `"ccc" -> "3(3)"`, `"jj" -> "10#(2)"` ### Task Return an integer array `counts` of length 26, where `counts[0]` is the number of `'a'` characters in the decoded string, `counts[1]` is the number of `'b'`, …, and `counts[25]` is the number of `'z'`. ### Examples - `s = "1226#24#"` decodes to `"abzx"`. - `s = "1(2)23(3)"` decodes to `"aabccc"`. - `s = "2110#(2)"` decodes to `"bajj"`. - `s = "23#(2)24#25#26#23#(3)"` decodes to `"wwxyzwww"`. ### Input/Output - **Input:** a string `s` consisting of digits, `#`, `(`, and `)` that follows the encoding rules above. - **Output:** an array of 26 integers with letter frequencies. ### Notes / Constraints (reasonable interview assumptions) - `s` is validly encoded. - Counts in parentheses can be multiple digits (e.g., `(12)`). - Aim for `O(|s|)` time and `O(1)` extra space (excluding the output array).

Quick Answer: This question evaluates proficiency in string parsing and frequency aggregation, specifically handling mixed-length encodings, tokenization of digits and '#' markers, and parsing numeric repetition counts while respecting linear-time and constant-space constraints.

You are given an encoded string `s` representing a string of lowercase English letters (`a`-`z`). The encoding follows these rules: 1. Letters `a` to `i` are encoded as digits `1` to `9` (`a -> "1"`, `b -> "2"`, ..., `i -> "9"`). 2. Letters `j` to `z` are encoded as two digits followed by `#` (`j -> "10#"`, `k -> "11#"`, ..., `z -> "26#"`). 3. If a letter repeats **consecutively** `k >= 2` times, the repetition is encoded by appending `"(k)"` immediately after that letter's code (`"aa" -> "1(2)"`, `"ccc" -> "3(3)"`, `"jj" -> "10#(2)"`). **Task:** Return an integer array `counts` of length 26, where `counts[0]` is the number of `'a'` characters in the decoded string, `counts[1]` is the number of `'b'`, ..., and `counts[25]` is the number of `'z'`. **Examples** - `s = "1226#24#"` decodes to `"abzx"`. - `s = "1(2)23(3)"` decodes to `"aabccc"`. - `s = "2110#(2)"` decodes to `"bajj"`. - `s = "23#(2)24#25#26#23#(3)"` decodes to `"wwxyzwww"`. **Notes / Constraints** - `s` is validly encoded. - Counts in parentheses can be multiple digits (e.g., `(12)`). - Aim for `O(|s|)` time and `O(1)` extra space (excluding the output array).

Constraints

  • s is a valid encoding produced by the rules above.
  • Single-letter codes are 1..9 (a..i); two-letter codes are 10#..26# (j..z).
  • A repetition suffix (k) appears only after a letter code, with k >= 2; k may have multiple digits.
  • Output is exactly 26 integers, index 0 = 'a' through index 25 = 'z'.

Examples

Input: ("1226#24#",)

Expected Output: [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1]

Explanation: Decodes to "abzx": 1->a, 2->b, 26#->z, 24#->x.

Input: ("1(2)23(3)",)

Expected Output: [2, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

Explanation: Decodes to "aabccc": 1(2)->aa, 2->b, 3(3)->ccc.

Input: ("2110#(2)",)

Expected Output: [1, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

Explanation: Decodes to "bajj": 2->b, 1->a, 10#(2)->jj.

Input: ("23#(2)24#25#26#23#(3)",)

Expected Output: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 1, 1, 1]

Explanation: Decodes to "wwxyzwww": 23#(2)->ww, 24#->x, 25#->y, 26#->z, 23#(3)->www. Total w=5, x=1, y=1, z=1.

Input: ("",)

Expected Output: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

Explanation: Empty input decodes to the empty string; all counts are zero.

Input: ("1(12)26#",)

Expected Output: [12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]

Explanation: Multi-digit repeat count: 1(12)->twelve a's, 26#->z.

Input: ("9",)

Expected Output: [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

Explanation: Single single-digit letter: 9->i.

Hints

  1. Scan left to right. The only way to tell a two-digit letter (10#..26#) from a single digit is to peek two characters ahead for a '#'.
  2. After consuming a letter's code, check whether the next character is '('. If so, read the integer up to ')' — it can be more than one digit — and use it as the multiplier; otherwise the letter occurs once.
  3. Map the numeric value v (1..26) to array index v-1 and add the repetition count there.
Last updated: Jun 26, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Solve Five Coding Problems - Oracle (medium)
  • Count closed islands in a grid - Oracle (easy)
  • Implement in-memory data structures and booking API - Oracle (hard)
  • Return a valid course completion order - Oracle (medium)
  • Implement an LRU cache - Oracle (medium)