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.Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free