← Oracle Interview Insights

Oracle·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Oracle SWE interview with a string manipulation problem that looked easy but had a few gotchas worth thinking through beforehand.

Questions Asked (1)

Q1

Given a list of phrases and a list of words, for each phrase find the 0-based index of the first word in that phrase that is an anagram of any word in the list. Return -1 for phrases with no match.

Algorithms & Data Structures
Author's notes

My first instinct was to sort the characters of every candidate word and stick them in a set, then do the same for each word in each phrase as I scanned through.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Preprocess the list of words by computing a canonical signature for each word (e.g., sorted characters) and storing them in a hash set for O(1) lookups. Then, for each phrase, split it into words, compute the signature for each word in order, and check against the set; return the index of the first match or -1 if none. This yields O(total characters) time and O(total unique words) space.

Pro tip: Mention that sorting each word is O(k log k) where k is word length, but you can optimize to O(k) using a frequency count of 26 letters (or a hash map for Unicode) as the signature, which is more efficient for long words. Also, clarify edge cases like empty strings, case sensitivity, and duplicate words in the list.

1. Clarify requirements and edge cases

Confirm assumptions: case sensitivity, definition of anagram (same characters, same frequency), handling of empty strings, and whether words in the list can be reused. Ask about input size to choose the right approach.

2. Design the anagram detection method

Choose a canonical representation for anagrams: sorted string or character frequency count. Explain that two words are anagrams if their canonical forms are equal.

3. Preprocess the word list

Compute the canonical form for each word in the list and store them in a hash set for O(1) average lookup. This allows quick checking of any word.

4. Process each phrase

For each phrase, split it into words. Iterate through the words in order, compute the canonical form, and check if it exists in the set. Return the index of the first match; if none, return -1.

5. Analyze complexity and optimize

State time complexity: O(W * L + P * W_p * L_p) where W is number of words, L average length, P number of phrases, W_p words per phrase. Space: O(W * L) for the set. Discuss potential optimizations like early exit and using frequency arrays.

Key Points to Mention

  • Canonical representation of anagrams: sorted characters or frequency count
  • Hash set for O(1) average lookup of anagram signatures
  • Time and space complexity analysis
  • Edge cases: empty strings, case sensitivity, duplicate words, no match
  • Early termination when first match is found
  • Trade-offs between sorting and frequency counting for signature generation

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