MEDIUMasked at 3 companies

Most Stones Removed with Same Row or Column

A medium-tier problem at 62% community acceptance, tagged with Hash Table, Depth-First Search, Union Find. Reported in interviews at PhonePe and 2 others.

Founder's read

Most Stones Removed with Same Row or Column hits your assessment without warning. You see a grid of stones, each at a position (row, col), and you're asked how many can be removed if stones sharing a row or column can knock each other out. The trick isn't simulation. It's recognizing that stones form connected components, and you can remove all but one stone per component. PhonePe, thoughtspot, and Tekion all ask it. Most candidates miss the graph structure hiding in the problem statement and code a greedy or simulation approach that either times out or fails edge cases. If this lands on your OA and you freeze on the pattern, StealthCoder solves it in seconds, invisible to the proctor.

Companies asking
3
Difficulty
MEDIUM
Acceptance
62%

Companies that ask "Most Stones Removed with Same Row or Column"

If this hits your live OA

Most Stones Removed with Same Row or Column is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made for the engineer who has done the work but might still blank with a webcam pointed at him.

Get StealthCoder
What this means

The mental wall is here: your brain reads 'same row or column' and wants to iterate, greedy-select, and repeat. That fails because the dependency chain is hidden. What actually happens is that each stone is a node, and two stones connect if they share a row or column. Stones in the same connected component can all vanish except one, because they form a chain of knockouts. Union Find is the cleanest tool. Iterate through stones, union any two that share a row or column by tracking which row and column you've seen. At the end, count how many unique parent sets exist, subtract from total stone count. Depth-First Search also works if you build an adjacency list and count components. Common failure: building a full graph naively, O(n²) checks, then timing out. The win is using Hash Table to track row and column assignments in one pass. StealthCoder handles both approaches and surfaces the Union Find code instantly if you're stuck mid-interview.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Most Stones Removed with Same Row or Column recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made for the engineer who has done the work but might still blank with a webcam pointed at him. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Most Stones Removed with Same Row or Column interview FAQ

Is this really just a connected components problem?+

Yes. Every stone can reach other stones through a chain of shared rows or columns. Each connected component can lose all but one stone. The problem is asking you to count components and return total minus component count. Union Find or DFS counts components in one pass.

Will a greedy or simulation approach work?+

No. Greedy fails because you can't always predict which stone to remove first. Simulation is O(n²) or worse per removal step. You need to see the graph structure upfront. Union Find or DFS both run in near-linear time.

How do I avoid the O(n²) trap when checking 'same row or column'?+

Don't iterate all pairs. Use a Hash Table to map each row and column to the set of stone indices it contains. Union the stones within each row, then within each column. Single pass, linear cost.

Is this still asked at top companies?+

Yes. PhonePe, thoughtspot, and Tekion have all reported it. Medium difficulty and 62% acceptance rate mean it's a filter question, not a gimme. Expect it in phone screens and OAs.

Do I need to build an explicit graph or can I just use Union Find?+

Union Find is faster and cleaner. You never materialize edges. Map rows and columns to stone indices, iterate once, union within each row and column. Count the result.

Want the actual problem statement? View "Most Stones Removed with Same Row or Column" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.