Drop Moderation Bans Fully Contained in a Longer Ban

Last updated: November 29, 2026

Quick Overview

A user's moderation history is a list of ban windows [start, end]. Remove every ban fully covered by another ban (c <= a and b <= d) and return how many bans remain.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


A user's moderation history is a list of ban windows [start, end]. Remove every ban fully covered by another ban (c <= a and b <= d) and return how many bans remain.

A light interval problem in the style of Meta's phone screens, set in integrity tooling that cleans redundant enforcement records before showing a reviewer the history. The interviewer checks the sort order trick that makes a single pass correct, especially for bans that share a start.

What the Interviewer Expects
  • Sorts by start ascending and end descending
  • Explains why the tie-break matters for equal starts
  • Tracks the max end seen so far
  • Counts a ban as remaining only if it extends past that max
  • Clarifies how identical bans are treated
Key Topics to Cover
Sorting
Intervals
Greedy
Custom sort keys
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you return the remaining bans themselves?
  • What if partial overlaps should also be merged?
  • How would you handle this for millions of users in a batch job?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: list of inclusive [start, end] bans. Output: number of bans not covered by any other ban. Identical bans cover each other, so only one copy should remain; confirm that with the interviewer....

High-Level Design

Sort by start ascending and, on ties, end descending. Now any ban that could cover the current one appears earlier. Keep max_end over all bans seen. The current ban is covered exactly when its end i...


Submit Your Answer
Markdown supported