Level: Intern
Round: Online Assessment · Type: Coding · Difficulty: 6/10 · Duration: 120 min · Interviewer: Neutral
Topics: Algorithms, Data Structures, Greedy Algorithm, Hash Table
Location: San Francisco Bay Area
Interview date: 2025-04-09
Question: Determine the minimum number of recommendation engines required to process all sessions without overlapping. Each session requires exactly one recommendation engine.
Question: Find the keys where the recommended products differ between two algorithms. Only consider keys present in both algorithms' recommendations.
The coding questions I encountered were:
Question 1: An online streaming platform tracks n user sessions. Each session has a specific start and end time, provided as a 2D array, sessionTimings, of size n x 2, where each element represents the [startTime, endTime] of a session.
Implement a function that determines the minimum number of recommendation engines required to process all sessions without overlapping sessions. Each session requires exactly one recommendation engine.
The function getMinEngines will take one input:
int sessionTimings[n][2]: each session's start and end times
The function should return the minimum number of engines needed to process all sessions without overlapping recommendations.
Note: Sessions can end and begin at the same time on a single engine. For example, sessions with times [10, 15] and [15, 20] can be processed by the same engine.
Example: Suppose n = 5, sessionTimings = [[1, 4], [1, 5], [5, 6], [6, 10], [7, 9]]
Sessions 1 and 2 overlap, as do sessions 4 and 5, so at least 2 recommendation engines are required. Hence, the answer is 2.
Constraints • 1 ≤ n ≤ 2 * 10^5 • 1 ≤ sessionTimings[i][0] ≤ sessionTimings[i][1] ≤ 2 * 10^6
Question 2: In a product recommendation system, two key-value pairs, predictions1, and predictions2, are given as strings. They represent the product recommendations made by two different algorithms.
Implement a function to find the keys where the recommended products (values) differ between the two algorithms. If a key is present in only one algorithm's recommendations, it should not be considered.
The function getPredictionDiff takes two inputs:
string predictions1: product recommendations made by Algorithm 1 string predictions2: product recommendations made by Algorithm 2
The function should return a list of the keys where the recommendations differ between the two algorithms, sorted alphabetically.
Example:
predictions1 = '{"hello":"world","hi":"hello","you":"me"}' predictions2 = '{"hello":"world","hi":"helloo","you":"me"}'
The only common key where the values differ is "hi". Hence the answer is ["hi"].
Constraints • 1 ≤ |predictions1|, |predictions2| ≤ 10^5. Every key is distinct in each of the predictions. • There is no whitespace in the strings.