Rank Data Center Racks and Return the K Weakest by Healthy Servers

Last updated: November 29, 2026

Quick Overview

Each row of a binary matrix is a rack, with 1s (healthy servers) always before 0s. Return the indices of the k racks with the fewest healthy servers, breaking ties by lower index.

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

0

0

0 solved


Each row of a binary matrix is a rack, with 1s (healthy servers) always before 0s. Return the indices of the k racks with the fewest healthy servers, breaking ties by lower index.

A Google screen question in a fleet health setting, close to what an SRE dashboard would compute. The interviewer looks for binary search on each sorted row plus a heap or sort with a correct tie-break.

What the Interviewer Expects
  • Exploits sorted rows with binary search
  • Pairs (count, index) for the tie-break
  • Uses a bounded heap or a full sort with justification
  • States O(m log n + m log k)
  • Handles k equal to the number of racks
Key Topics to Cover
Binary Search
Heap
Top-K
Matrix
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
  • What if rows are not sorted?
  • What if racks stream in one at a time?
  • How would you keep this updated as servers flip health?
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: m x n matrix of 0/1, each row non-increasing (1s then 0s), and k with 1 <= k <= m.
  • Weakness of a rack = number of 1s; lower is weaker.
  • Ties: smaller row index is weaker.
  • Output: the k w...
High-Level Design

Because each row is sorted, the count of healthy servers is the position of the first 0, found by binary search in O(log n) rather than O(n). The pair (count, index) encodes both the primary key and...


Submit Your Answer
Markdown supported