← Oracle Interview Insights

Oracle·Software Engineer·Online Assessment (OA)·Intermediate

Intermediate
Jun 2026

Summary

Oracle SWE interview that came down to a single algorithmic problem. Not much ceremony around it, just the problem and figuring it out under pressure.

Questions Asked (1)

Q1

Find the maximum number of non-overlapping substrings from a given string such that each substring contains all occurrences of its characters.

Algorithms & Data Structures
Author's notes

This one took me a while to even understand what was being asked.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, compute the last occurrence index for each character in the string. Then, iterate through the string while maintaining the farthest last occurrence seen so far; when the current index reaches that farthest point, you've found a valid substring, so increment the count and reset for the next substring.

Pro tip: Clarify that the substrings must be contiguous and cover the entire string without overlap, and mention that the greedy approach works because extending a substring to include all occurrences of its characters is always optimal.

1. Understand the problem

Restate the problem to ensure clarity: we need to partition the string into the maximum number of contiguous, non-overlapping substrings such that each substring contains all occurrences of every character it includes.

2. Preprocess last occurrences

Create an array or hash map to store the last index of each character in the string. This will help determine how far a substring must extend to include all occurrences of its characters.

3. Greedy partitioning

Iterate through the string, keeping track of the farthest last occurrence seen so far. When the current index equals this farthest point, a valid substring ends; increment the count and reset the farthest point for the next substring.

4. Analyze complexity

Explain that the algorithm runs in O(n) time and O(1) space (since the alphabet size is fixed), making it optimal.

5. Test with examples

Walk through a simple example like 'abac' to demonstrate the algorithm: last occurrences: a->2, b->1, c->3. Start at 0, farthest=2, at index 2 farthest=2, so substring 'aba' ends, count=1; then 'c' ends, count=2.

Key Points to Mention

  • The substrings must be contiguous and cover the entire string without overlap.
  • Each substring must contain all occurrences of every character it includes.
  • The greedy approach is optimal: extending a substring to include all occurrences of its characters never reduces the number of possible substrings.
  • Time complexity is O(n) with a single pass after preprocessing.
  • Space complexity is O(1) if using a fixed-size array for last occurrences (assuming ASCII).
  • Edge cases: empty string, string with all unique characters, string with all same characters.

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