Scale AI software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
Subsequence Goodness Values
Input: Array(neighborhood_id, start, end).First, compute the maximal activity windows for every neighborhood. A neighborhood is active whenever at least one of its parties is in progress. Clip party intervals to the reporting horizon, discard empty intervals, and merge overlapping or touching intervals. Multiple simultaneous parties in one neighborhood still count as only one active neighborhood.Next, use these neighborhood windows to calculate each town's quiet windows. A town is quiet whenever the number of distinct active neighborhoods is strictly less than its threshold. Return its maximal quiet windows and the sum of their durations. A threshold of 1 recovers the reported interview's time-without-parties behavior.All intervals are half-open: an interval ending at time t is inactive at t, while one starting at t is active. Changes at the same timestamp happen simultaneously. Return every configured neighborhood and town, including those without parties. A town's threshold may exceed its number of neighborhoods, in which case it is quiet throughout the horizon.Return a JSON-compatible object with these fields:neighborhood_windows: neighborhood ID → chronologically ordered list of [start, end] windows.town_quiet_windows: town ID → chronologically ordered list of [start, end] windows.town_quiet_duration: town ID → integer total quiet duration.analyze_activity(neighborhood_to_town: dict[str, str], town_thresholds: dict[str, int], parties: list[tuple[str, int, int]], window_start: int, window_end: int) -> dict[str, object]{
"neighborhood_to_town": {"a": "X", "b": "X", "c": "Y"},
"town_thresholds": {"X": 2, "Y": 1},
"parties": [
["a", 1, 5],
["a", 3, 7],
["b", 4, 9],
["c", -2, 2],
["c", 10, 15]
],
"window_start": 0,
"window_end": 12
}Output:{
"neighborhood_windows": {
"a": [[1, 7]],
"b": [[4, 9]],
"c": [[0, 2], [10, 12]]
},
"town_quiet_windows": {
"X": [[0, 4], [7, 12]],
"Y": [[2, 10]]
},
"town_quiet_duration": {"X": 9, "Y": 8}
}Explanation: Neighborhood a's overlapping parties merge into [1, 7). Town X reaches its threshold of two active neighborhoods only during [4, 7), so its quiet duration is 4 + 5 = 9. Town Y has no active neighborhood during [2, 10), giving duration 8. Parties in c are clipped to the horizon.Example 2:Input:{
"neighborhood_to_town": {"a": "X", "b": "X", "c": "Y"},
"town_thresholds": {"X": 1, "Y": 1},
"parties": [
["a", 0, 3],
["a", 3, 6],
["b", 6, 10],
["b", 2, 2],
["a", -5, 0],
["c", 12, 14]
],
"window_start": 0,
"window_end": 10
}Output:{
"neighborhood_windows": {
"a": [[0, 6]],
"b": [[6, 10]],
"c": []
},
"town_quiet_windows": {"X": [], "Y": [[0, 10]]},
"town_quiet_duration": {"X": 0, "Y": 10}
}Explanation: Touching parties in a merge. At time 6, a becomes inactive while b becomes active, so X never becomes quiet. The zero-duration party and parties entirely outside the horizon contribute nothing. Town Y is quiet for all 10 time units.Constraints:0 <= len(parties) <= 200000.0 <= len(neighborhood_to_town) <= 100000; 1 <= len(town_thresholds) <= 100000.[-10^12, 10^12]; party records satisfy start <= end, and window_start < window_end.[1, 100000]. Towns may have no configured neighborhoods.class TaskScheduler: def add_task(self, task_id: str, dependencies: List[str]) -> None: # Adds a new task with its dependencies.def schedule_tasks(self) -> List[str]: # Returns a list of tasks in the order they should be executed.Example 1: add_task('A', []) add_task('B', ['A']) add_task('C', ['A']) ['A', 'B', 'C'] add_task('D', ['E']) add_task('E', []) ['E', 'D'] def schedule_tasks(tasks: List[str], dependencies: List[Tuple[str, str]]) -> List[str]: tasks = ['A', 'B', 'C'], dependencies = [('A', 'B'), ('B', 'C')] ['C', 'B', 'A'] tasks = ['A', 'B', 'C', 'D'], dependencies = [('A', 'B'), ('B', 'C'), ('D', 'B')] ['D', 'C', 'B', 'A'] def add_task(self, task_id: str, dependencies: List[str]) -> None: def execute(self) -> List[str]: scheduler.add_task('A', []) scheduler.add_task('B', ['A']) scheduler.execute() ['A', 'B'] scheduler.add_task('C', ['D']) scheduler.add_task('D', []) scheduler.add_task('A', ['C']) scheduler.execute() ['D', 'C', 'A'] def schedule_tasks(tasks: List[int], dependencies: List[Tuple[int, int]]) -> List[int]: tasks = [1, 2, 3], dependencies = [(1, 2), (1, 3)][1, 2, 3]tasks = [1, 2, 3], dependencies = [(1, 2), (2, 1)][]1 ≤ len(tasks) ≤ 10001 ≤ len(dependencies) ≤ 5000[1, len(tasks)].def task_scheduler(tasks: List[int], dependencies: List[Tuple[int, int]]) -> List[int]:tasks = [1, 2, 3, 4], dependencies = [(1, 2), (1, 3), (3, 4)][1, 3, 4, 2] (possible output)tasks = [1, 2, 3], dependencies = [(1, 2), (2, 1)][]TaskScheduler that manages a list of tasks, each with a set of dependencies. You will need to create a method schedule_tasks that takes the list of tasks and their dependencies and returns an ordered list of tasks that can be executed respecting the dependencies. If there are circular dependencies, return an empty list. def schedule_tasks(tasks: List[str], dependencies: List[Tuple[str, str]]) -> List[str]: tasks = ['A', 'B', 'C', 'D']
dependencies = [('A', 'B'), ('B', 'C'), ('C', 'D')] ['D', 'C', 'B', 'A']
D can be completed first as it has no dependencies, followed by C, B, and finally A. tasks = ['A', 'B', 'C']
dependencies = [('A', 'B'), ('B', 'A')] []
A and B, making it impossible to schedule them. 1 <= len(tasks) <= 10^4 0 <= len(dependencies) <= 10^4 Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free