Count Contiguous Runs of Selected Servers in a Linked Rack
Last updated: November 29, 2026
Quick Overview
Servers in a rack are a singly linked list of unique IDs, and an alert names a subset of those IDs. Count how many maximal contiguous segments of the list consist only of alerted servers.
0
0
0 solved
Servers in a rack are a singly linked list of unique IDs, and an alert names a subset of those IDs. Count how many maximal contiguous segments of the list consist only of alerted servers.
A Google phone screen problem in a datacenter alerting framing, testing whether you can count segments by detecting their ends rather than tracking state awkwardly. The interviewer also expects a set for O(1) membership.
What the Interviewer Expects
- Store the alert subset in a hash set
- Count a segment when an alerted node is followed by a non-alerted node or the end
- Single pass, no extra list
- Handle alerts naming nodes that are scattered or all adjacent
- State O(n + k) time
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Return the longest such segment.
- The rack is circular; adjust the count for a segment that wraps.
- Alerts change frequently; maintain the count incrementally.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: head of a list of unique IDs and a collection
alerted(subset of IDs). - Output: number of maximal runs of consecutive alerted nodes.
- O(n + k) time....
High-Level Design
A run ends exactly at an alerted node whose successor is not alerted or does not exist. So walk the list once and count nodes that satisfy `node in alerted and (node.next is None or node.next not in a...