Count Servers That Share a Row or Column With Another

Last updated: November 29, 2026

Quick Overview

A grid marks rack positions with 1 for a server and 0 for empty. Two servers can communicate if they are in the same row or the same column; return how many servers can communicate with at least one other server.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

0

0 solved


A grid marks rack positions with 1 for a server and 0 for empty. Two servers can communicate if they are in the same row or the same column; return how many servers can communicate with at least one other server.

A short Meta online assessment problem framed around rack wiring in a data center hall. The interviewer checks that you avoid an O(RC(R + C)) scan by precomputing row and column counts. It also gives a quick read on whether you test sparse corner cases.

What the Interviewer Expects
  • Precompute server counts per row and per column
  • Count a server if its row or column count exceeds one
  • Avoid rescanning rows and columns per cell
  • Handle empty grids and isolated servers
  • State linear time and space
Key Topics to Cover
Counting
Matrix
Hashing
Precomputation
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 the input is a list of server coordinates in a 10^9 by 10^9 hall?
  • How would you count servers in the same connected group through shared rows and columns?
  • What if communication requires being within distance d in the row?
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
  • Grid up to 250 x 250.
  • A server counts if at least one other server is in its row or column.
  • Return that count....
High-Level Design

A server is isolated exactly when it is the only server in its row and the only server in its column. So compute row_count and col_count in one pass, and in a second pass count servers where eithe...


Submit Your Answer
Markdown supported