Deduplicate Homepage Content Across Rows
Learn this problemProblem statement
You are given ordered homepage content rows in rows. Process the rows from top to bottom and the titles within each row from left to right.
For an ordinary row, its first globalLimits[r] retained titles participate in global deduplication:
- If a title has already been retained in the global portion of an earlier ordinary row, skip it.
- Otherwise, retain it and add it to the global set.
After the row has retained its global-limit titles, retain later titles only if that title has not already been retained in the same row. A title rejected by global deduplication does not count toward the row's retained-title limit.
If exemptRows[r] is true, the entire row uses only row-local deduplication and neither reads nor changes the global set.
For this exercise, assume titles are compared by exact, case-sensitive string equality. In every row, retain the first eligible occurrence of each title. Return all filtered rows in their original order.
Function
deduplicateHomepageRows(rows: String[][], globalLimits: int[], exemptRows: boolean[]) → String[][]Examples
Example 1
rows = [["A","B","A","C"],["B","D","B","E"],["A","F","A"]]globalLimits = [2,2,1]exemptRows = [false,false,true]return = [["A","B","C"],["D","E"],["A","F"]]The first row globally retains A and B, then retains C locally. In the second row, global duplicates of B are skipped, so D and E fill its two global positions. The third row is exempt and keeps the first row-local occurrence of A and F.
Example 2
rows = [["x","x","y"],["x","z","x"]]globalLimits = [0,0]exemptRows = [false,false]return = [["x","y"],["x","z"]]Both global limits are zero, so each row independently keeps only its first occurrence of each title.
Constraints
rows.length == globalLimits.lengthrows.length == exemptRows.length- Every value in
globalLimitsis nonnegative. - Titles are compared using exact, case-sensitive string equality.
More Netflix problems
- Count String Pairs With Disjoint CharactersPHONE SCREEN · Seen Aug 2026
- Longest Consecutive Identical Character RunPHONE SCREEN · Seen Aug 2026
- Longest Substring Without Repeating CharactersPHONE SCREEN · Seen Aug 2026
- Movie Billboard RotationONSITE INTERVIEW · Seen Jul 2026
- Topological Sort for Ads TasksPHONE SCREEN · Seen Jun 2026
- Command Undo Data StructureONSITE INTERVIEW · Seen Apr 2026
- Timed Cache with Sidecar CleanupONSITE INTERVIEW · Seen Apr 2026