← Oracle Interview Insights

Oracle·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Oracle SWE interview with a data structures problem that looked deceptively simple but had a real O(1) constraint that forced you to think carefully about how you track state. One question, but it had enough depth to keep me busy for a while.

Questions Asked (1)

Q1

Design a data structure that tracks a stream of user login events and supports two O(1) operations: recording a login for a user ID, and returning the earliest user who has logged in exactly once so far.

Algorithms & Data StructuresSystem Design
Author's notes

I got the basic idea pretty fast.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the requirements and constraints, then propose a design using a doubly linked list to maintain the order of users who have logged in exactly once, combined with a hash map for O(1) access to each user's node and login count. Explain how recording a login updates the count and moves the user in or out of the list, ensuring both operations remain O(1).

Pro tip: Mention edge cases like duplicate logins and users who log in again after being in the once-list, and discuss how to handle them without breaking O(1) operations. Also, briefly compare with alternative approaches (e.g., two hash maps) to show depth.

1. Clarify Requirements

Ask about the definition of 'earliest' (e.g., first login time or insertion order), whether user IDs are bounded, and if the stream is infinite. Confirm that both operations must be strictly O(1) time.

2. Choose Data Structures

Propose a doubly linked list to maintain the order of users with exactly one login, and a hash map from user ID to a node containing login count and a pointer to the list node. This allows O(1) updates and access.

3. Define Operations

For recordLogin(userId): increment the user's login count. If it becomes 1, append the user to the end of the list. If it becomes 2, remove the user's node from the list. For getEarliestOnce(): return the head of the list if non-empty, else null.

4. Handle Edge Cases

Discuss what happens when a user logs in more than twice (count >2), when the list is empty, and when a user who was removed logs in again (count becomes 3, no list change). Ensure no duplicate entries in the list.

5. Analyze Complexity

Confirm that both operations are O(1) time and O(n) space, where n is the number of distinct users. Mention that the linked list operations (append, remove) are O(1) given direct node access.

Key Points to Mention

  • Use of a doubly linked list to maintain insertion order of users with exactly one login.
  • Hash map mapping user ID to a node containing login count and a pointer to the linked list node.
  • O(1) update: increment count, and if count transitions to 1 or 2, add/remove from list accordingly.
  • O(1) retrieval: return the head of the linked list (earliest user with exactly one login).
  • Handling of users with more than one login: they are removed from the list and never re-added.
  • Space complexity: O(n) for n distinct users, and time complexity: O(1) per operation.

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