← Oracle Interview Insights

Oracle·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Oracle SWE coding round, one problem the whole session. The question looked like a parsing exercise but the O(n) constraint meant you had to think carefully about how you scanned the string.

Questions Asked (1)

Q1

Given an encoded string, decode it into a 26-element integer array representing letter frequencies. Letters a-i map to digits '1'-'9'; letters j-z map to two-digit numbers followed by '#' (e.g. '10#' for j). Immediately after a letter's encoding, an optional parenthesized integer like '(7)' means that letter repeats that many times; no parenthesis means it appears once. Return int[26] where index i is the count of the (i+1)-th letter. Must run in O(n).

Algorithms & Data Structures
Author's notes

My first instinct was to just iterate left to right and parse greedily, but the '#' suffix for two-digit codes means you don't know if a digit is standalone or part of a two-digit code until you look ahead.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a single pass through the string with an index pointer. At each position, determine if the letter is single-digit (1-9) or two-digit (10-26) by checking if the next character is '#'. Then check for an optional '(count)' immediately after and add the count (or 1) to the corresponding frequency array index. This yields O(n) time and O(1) extra space (besides the output array).

Pro tip: Clarify edge cases upfront: what if the repeat count is 0? What if the string is empty? Also, mention that you can avoid string slicing by parsing the number character by character to keep it truly O(n) and efficient.

1. Initialize and set up pointers

Create an int[26] result array initialized to zeros. Use an index i to traverse the string from left to right.

2. Decode the letter

If s[i] is a digit and s[i+1] is '#', the letter is two-digit: compute value = (s[i]-'0')*10 + (s[i+1]-'0'), then advance i by 2. Otherwise, the letter is single-digit: value = s[i]-'0', advance i by 1. The letter index is value-1.

3. Parse optional repeat count

If the next character is '(', parse the integer until ')', then advance i past the ')'. Otherwise, the repeat count is 1.

4. Update frequency and continue

Add the repeat count to result[letterIndex]. Continue the loop until i reaches the end of the string.

5. Return the result array

After processing all characters, return the int[26] array containing the letter frequencies.

Key Points to Mention

  • Single-pass O(n) time complexity with O(1) auxiliary space (output array is required).
  • Handling both single-digit (1-9) and two-digit (10-26) encodings correctly, including the '#' delimiter.
  • Parsing the optional parenthesized repeat count efficiently without using expensive string operations like split or substring.
  • Edge cases: empty string, repeat count of 0, and ensuring no out-of-bounds access when checking for '#' or '('.
  • Mapping the decoded number to the correct array index (value - 1) for letters a-z.
  • Clarifying assumptions with the interviewer (e.g., valid input format, no leading zeros) before coding.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.