Level: Junior-Level
Round: Online Assessment · Type: Coding · Difficulty: 6/10 · Duration: 120 min · Interviewer: Neutral
Topics: Algorithms, Data Structures, Arrays, Machine Learning
Location: San Francisco Bay Area
Interview date: 2026-01-06
Question: Given arrays of timestamps for user events and corresponding user IDs, find the total number of sessions across all users.
Question: Implement a function that determines how many valid ensembles can be formed based on model accuracy scores.
Given arrays of timestamps for user events and corresponding user IDs, find the total number of sessions across all users. A session for a user is defined as a contiguous sequence of events such that no two consecutive events for that user are separated by more than timeout seconds.
Any gap greater than timeout seconds between consecutive events for the same user starts a new session.
The function getSessionCount will take three inputs:
int timeout: the maximum allowed gap (in seconds) between two consecutive events for a sessionstring userIds[n]: user ID for each eventint timestamps[n]: timestamp (in seconds) for each eventThe function should return an integer denoting the total number of sessions across all users.
Example:
timeout = 10 userIds = ["u1", "u1", "u1", "u2", "u2", "u2", "u2"] timestamps = [1, 5, 17, 3, 10, 20, 35]
The table below shows the total number of sessions for each user:
User | Timestamps | Sessions | Session Counts -----|------------|----------|---------------- u1 | [1, 5, 17] | [1, 5], [17] | 2 u2 | [3, 10, 20, 35] | [3, 10, 20], [35] | 2
The total number of sessions for all users = 2 + 2 = 4.
A machine learning team is building ensembles by selecting models based on their accuracy scores, represented by the array modelAccuracies.
A valid ensemble must satisfy the following conditions:
Implement a function that determines how many valid ensembles can be formed.
The function countValidEnsembles takes four inputs:
int modelAccuracies[n]: the accuracy scores of available modelsint minModels: the minimum number of models required in an ensembleint minAccuracy: the minimum allowed accuracy score of a model in an ensembleint maxAccuracy: the maximum allowed accuracy score of a model in an ensembleThe function should return the number of valid ensembles that can be formed.
Example:
modelAccuracies = [12, 4, 6, 13, 5, 10] minModels = 3 minAccuracy = 4 maxAccuracy = 10
Filter models with accuracy within the range [4, 10]: [4, 6, 5, 10]. Calculate the number of valid ensembles. At least minModels = 3 models are required for an ensemble.