PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Oracle

Find users with at least one valid session

Last updated: Mar 29, 2026

Quick Overview

This question evaluates the ability to parse and process event logs, pair signin/signout events per user, and handle unordered timestamps and per-user state with time-window constraints.

  • medium
  • Oracle
  • Coding & Algorithms
  • Software Engineer

Find users with at least one valid session

Company: Oracle

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given: - A list of log entries `logs`, where each entry is a string in the format: ``` "userId action timestamp" ``` - `userId` is a non-empty string without spaces (e.g., `"u1"`). - `action` is either `"signin"` or `"signout"`. - `timestamp` is an integer representing time in seconds. - An integer `maxTime`. A **session** for a user is defined as a pair of actions: - A `"signin"` log for that user at time `t_in`, and - The **next** `"signout"` log for the same user at time `t_out` such that `t_out > t_in`, - And that `signout` has not already been paired with a previous `signin` for that user. A session is **valid** if: ```text (t_out - t_in) <= maxTime ``` Your task is to: > Return the set (or list) of all `userId`s that have **at least one** valid session. Additional details and assumptions: - The `logs` list may **not** be sorted by time; you should handle that. - Each log belongs to exactly one user, determined by `userId`. - If there is a `signout` without any earlier unmatched `signin` for that user, ignore that `signout`. - If there is a `signin` without any later `signout`, it does not form a session. - A single user may have multiple sessions; if **any one** of them is valid, that user should be included in the output. - The output can be in any order. **Example** ```text logs = [ "u1 signin 1", "u2 signin 2", "u1 signout 5", "u2 signout 20", "u1 signin 30", "u1 signout 35" ] maxTime = 10 ``` - For `u1`: - Session 1: signin at 1, signout at 5 → duration 4 (valid) - Session 2: signin at 30, signout at 35 → duration 5 (valid) - For `u2`: - Session 1: signin at 2, signout at 20 → duration 18 (invalid if `maxTime = 10`) So the output should include `"u1"` (has valid sessions) and exclude `"u2"`. Implement a function that, given `logs` and `maxTime`, returns all such `userId`s.

Quick Answer: This question evaluates the ability to parse and process event logs, pair signin/signout events per user, and handle unordered timestamps and per-user state with time-window constraints.

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
Nov 11, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
4
0

You are given:

  • A list of log entries logs , where each entry is a string in the format:
    "userId action timestamp"
    
    • userId is a non-empty string without spaces (e.g., "u1" ).
    • action is either "signin" or "signout" .
    • timestamp is an integer representing time in seconds.
  • An integer maxTime .

A session for a user is defined as a pair of actions:

  • A "signin" log for that user at time t_in , and
  • The next "signout" log for the same user at time t_out such that t_out > t_in ,
  • And that signout has not already been paired with a previous signin for that user.

A session is valid if:

(t_out - t_in) <= maxTime

Your task is to:

Return the set (or list) of all userIds that have at least one valid session.

Additional details and assumptions:

  • The logs list may not be sorted by time; you should handle that.
  • Each log belongs to exactly one user, determined by userId .
  • If there is a signout without any earlier unmatched signin for that user, ignore that signout .
  • If there is a signin without any later signout , it does not form a session.
  • A single user may have multiple sessions; if any one of them is valid, that user should be included in the output.
  • The output can be in any order.

Example

logs = [
  "u1 signin 1",
  "u2 signin 2",
  "u1 signout 5",
  "u2 signout 20",
  "u1 signin 30",
  "u1 signout 35"
]
maxTime = 10
  • For u1 :
    • Session 1: signin at 1, signout at 5 → duration 4 (valid)
    • Session 2: signin at 30, signout at 35 → duration 5 (valid)
  • For u2 :
    • Session 1: signin at 2, signout at 20 → duration 18 (invalid if maxTime = 10 )

So the output should include "u1" (has valid sessions) and exclude "u2".

Implement a function that, given logs and maxTime, returns all such userIds.

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.