PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Oracle

Design structure for first unique login user

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's ability to design an efficient online data structure that maintains a stream of login events and supports constant-time updates and queries for the earliest user with exactly one login.

  • easy
  • Oracle
  • Coding & Algorithms
  • Software Engineer

Design structure for first unique login user

Company: Oracle

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

You are given an online stream of user login events. Each event is a user ID (e.g., an integer or string) indicating that this user has just logged in. You need to design a data structure that supports **two operations**: 1. `login(userId)` Record that `userId` has logged in **one more time**. 2. `firstUser()` Return the ID of the user who - has logged in **exactly once** so far, and - among all such users, is the **earliest** by login time (i.e., the one whose first login happened earliest in the stream), or return a special value (e.g., `null` or `-1`) if no such user exists. **Requirements:** - Both `login` and `firstUser` must run in **O(1) worst-case time per operation**. - You can assume the number of distinct users fits in memory. - You may choose any reasonable representation for `userId` (e.g., integer or string), but specify your assumptions. **Example:** Suppose the login stream is: - `login(A)` // A has logged in once - `login(B)` // B has logged in once; A is still first unique - `login(A)` // A now has logged in twice - `login(C)` // C has logged in once Then the sequence of `firstUser()` calls should return: - After `login(A)`: `firstUser()` → `A` - After `login(B)`: `firstUser()` → `A` (A and B are unique, A is earlier) - After `login(A)`: `firstUser()` → `B` (A is no longer unique) - After `login(C)`: `firstUser()` → `B` (B is still the earliest unique user) Design the data structure and its operations to meet the time complexity guarantees. You do **not** need to handle persistence or multi-threading; focus on the core algorithm and data organization.

Quick Answer: This question evaluates a candidate's ability to design an efficient online data structure that maintains a stream of login events and supports constant-time updates and queries for the earliest user with exactly one login.

Related Interview Questions

  • Solve Five Coding Problems - Oracle (medium)
  • Compute letter frequencies from encoded string - Oracle (medium)
  • Count closed islands in a grid - Oracle (easy)
  • Implement in-memory data structures and booking API - Oracle (hard)
  • Implement an LRU cache - Oracle (medium)
Oracle logo
Oracle
Oct 12, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
2
0

You are given an online stream of user login events. Each event is a user ID (e.g., an integer or string) indicating that this user has just logged in.

You need to design a data structure that supports two operations:

  1. login(userId)
    Record that userId has logged in one more time .
  2. firstUser()
    Return the ID of the user who
    • has logged in exactly once so far, and
    • among all such users, is the earliest by login time (i.e., the one whose first login happened earliest in the stream), or return a special value (e.g., null or -1 ) if no such user exists.

Requirements:

  • Both login and firstUser must run in O(1) worst-case time per operation .
  • You can assume the number of distinct users fits in memory.
  • You may choose any reasonable representation for userId (e.g., integer or string), but specify your assumptions.

Example:

Suppose the login stream is:

  • login(A) // A has logged in once
  • login(B) // B has logged in once; A is still first unique
  • login(A) // A now has logged in twice
  • login(C) // C has logged in once

Then the sequence of firstUser() calls should return:

  • After login(A) : firstUser() → A
  • After login(B) : firstUser() → A (A and B are unique, A is earlier)
  • After login(A) : firstUser() → B (A is no longer unique)
  • After login(C) : firstUser() → B (B is still the earliest unique user)

Design the data structure and its operations to meet the time complexity guarantees. You do not need to handle persistence or multi-threading; focus on the core algorithm and data organization.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Oracle•More Software Engineer•Oracle Software Engineer•Oracle Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.