Find Max Num Of Servers
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Amazon asked this in April 2025, and it's a matrix traversal problem that looks simple until you realize you need to count servers efficiently across rows and columns. You're given a grid where some cells contain servers, and you need to find how many servers can communicate (share a row or column with at least one other server). It's a two-pass problem, not a complex algorithm. StealthCoder will catch the edge case logic if you blank on the exact counting rules.
Pattern and pitfall
The pattern here is straightforward but easy to mess up: first pass counts how many servers exist in each row and column, second pass marks which servers are isolated. A server communicates if its row count is greater than 1 OR its column count is greater than 1. Most candidates overthink this and try to do it in one pass or overcomplicate the logic. The trick is storing the row and column sums, then a simple linear scan to count. If you panic on the live OA, StealthCoder can feed you the two-pass structure and the exact condition without you having to reconstruct it.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Find Max Num Of Servers cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Find Max Num Of Servers FAQ
Is this really just counting servers by row and column?+
Yes. Count servers in each row and column first, then iterate again and sum up servers that have row count > 1 or column count > 1. No DFS, no BFS, no complex graph logic. Most of the problem is avoiding off-by-one errors.
What's the most common mistake?+
Trying to do it in one pass and getting confused about which servers are isolated. Also, mixing up the logic: a server communicates if its row OR column has other servers, not both. Keep row and column frequency maps separate.
Do I need to mark servers as visited or track connections?+
No. This is not a connectivity problem. You just need counts. If a server's row count > 1, it can talk to someone in that row. If column count > 1, it can talk to someone in that column. No marking or traversal needed.
What's the time and space complexity?+
Time is O(m*n) for two passes through the grid. Space is O(m + n) for the row and column frequency maps. This is optimal and Amazon knows it. No tricks to optimize further.
How do I prepare in 48 hours?+
Understand what 'communicate' means in this problem first. Then code the two-pass solution cleanly. Test on edge cases: empty grid, all isolated servers, entire grid filled. That's it. Don't over-prepare this one.