← Oracle Interview Insights

Oracle·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Oracle SWE interview with a string decoding problem that looks straightforward until you actually try to parse it correctly in linear time. One question, pretty focused, felt more like a coding screen than a full loop.

Questions Asked (1)

Q1

Given an encoded string, decode it into a 26-element integer array representing letter frequencies. Single-digit characters '1'-'9' map to letters a-i, two-digit numbers followed by '#' (like '10#' through '26#') map to letters j-z, and an optional parenthesized count immediately after a letter encoding means that letter repeats that many times. Implement this in O(n).

Algorithms & Data Structures
Author's notes

The two-digit '#' suffix encoding is what trips you up if you're not careful.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a single left-to-right scan with an index pointer, parsing either a single digit or a two-digit number followed by '#', then checking for an optional parenthesized count to add to the frequency array. Maintain O(n) by advancing the pointer past each token and count without backtracking.

Pro tip: Clarify edge cases upfront—like counts with multiple digits, missing '#', or counts of zero—and state that you'll handle them defensively; this shows production-level thinking and avoids silent bugs.

1. Parse tokens with a pointer

Iterate through the string with an index i. If s[i+2] == '#', treat s[i..i+1] as a two-digit number and advance i by 3; otherwise treat s[i] as a single digit and advance i by 1.

2. Map token to letter index

Convert the parsed numeric value to a 0-based letter index: value - 1 for single digits, value - 1 for two-digit values (so '10#' -> 9 for 'j', '26#' -> 25 for 'z').

3. Handle optional parenthesized count

After the letter token, if the next character is '(', parse the integer inside parentheses (which may have multiple digits) and use it as the repeat count; otherwise default count to 1.

4. Accumulate frequency and advance

Add the count to freq[letterIndex], then advance the pointer past the closing ')' if a count was parsed, ensuring the pointer always moves forward for O(n) time.

5. Return the 26-element array

After the scan completes, return the frequency array; optionally validate that all characters were consumed and that counts are non-negative.

Key Points to Mention

  • Single-pass O(n) time and O(1) extra space (besides the 26-element output array).
  • Correctly distinguishing single-digit vs. two-digit tokens by checking for '#' at the right position.
  • Parsing multi-digit counts inside parentheses without using regex or split, to keep linear time.
  • Handling edge cases: count of 1 (no parentheses), count of 0, missing '#', and malformed input.
  • Mapping numeric values to 0-based indices: value - 1 for both single and two-digit cases.
  • Ensuring the pointer always advances to avoid infinite loops and maintain O(n).

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