Most Stones Removed with Same Row or Column
Updated
Problem statement
There are stones at distinct integer coordinates on a two-dimensional plane. A stone may be removed if another remaining stone shares its row or its column.
Return the maximum number of stones that can be removed.
Function
removeStones(stones: int[][]) → intExamples
Example 1
stones = [[0,0],[0,1],[1,0],[1,2],[2,1],[2,2]]return = 5All six stones form one connected component, so one must remain.
Example 2
stones = [[0,0],[0,2],[1,1],[2,0],[2,2]]return = 3Four corner stones are connected and the center stone is isolated, so two stones remain.
Constraints
1 <= stones.length <= 10000 <= stones[i][0], stones[i][1] <= 10000- All coordinates are distinct.
More Snap Inc. interview questions
- ID Allocator with Assign and ReleasePHONE SCREEN · Seen Nov 2026
- Basic Calculator IIPHONE SCREEN · Seen Oct 2026
- Stream Cluster Max and MedianPHONE SCREEN · Seen Oct 2026
- LRU Cache with Thread-Safety Follow-UpPHONE SCREEN · Seen Sep 2026
- Smallest Range Covering Elements from K ListsPHONE SCREEN · Seen Sep 2026
- Report Island Areas in Discovery OrderPHONE SCREEN · Seen Aug 2026
- Render an Org Chart and Find Skip-Level PairsONSITE INTERVIEW · Seen Nov 2026
- Peak of an Increasing-Then-Decreasing ArrayONSITE INTERVIEW · Seen Oct 2026
- Number of Closed IslandsONSITE INTERVIEW · Seen Oct 2026
- Radar Barrier CrossingONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Evaluate DivisionApple · PHONE SCREENApple interview questions
- Count Friend CirclesOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Count Connected Point ClustersGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Count the Number of Complete ComponentsAmazon · PHONE SCREEN
- Number of ProvincesSambaNova Systems · PHONE SCREENSambaNova Systems interview questions
- Count Islands in a GridDoorDash · PHONE SCREENDoorDash interview questions
- Path Existence in an Undirected GraphByteDance · PHONE SCREENByteDance interview questions
- Evaluate DivisionPlaud · ONSITE INTERVIEW
- Minimum Unreachable WarehousesVisa · OAVisa interview questions
- Visible Profiles CountMicrosoft · OAMicrosoft interview questions