NBCU / VO Interview Question: Video Home Page Recommendation System Design

16 Views
No Comments

Assume you work at a video streaming service and are asked to build a solution that will recommend videos to users on their home page. How would you approach this?

Given an integer array nums, return the third distinct maximum number in this array.

Example:

Input: [6,4,2,3]
Output: 3
Explanation:
The first distinct maximum is 6.
The second distinct maximum is 4.
The third distinct maximum is 3.

This problem combines a system-design style prompt with a clear algorithmic task: find the third distinct maximum in an integer array. The key is to ignore duplicates while tracking the top three unique values in a single pass. A common solution uses three variables and updates them as each number is scanned, which achieves O(n) time and O(1) extra space. For the example [6,4,2,3], the distinct maxima are 6, 4, and 3, so the answer is 3.

END
 0