FastPrepMost Stones Removed with Same Row or Column
Problems/Most Stones Removed with Same Row or Column

Most Stones Removed with Same Row or Column

Snap Inc. logoSnap Inc.● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Snap Inc. phone screen. The report describes the well-known stone-removal problem where stones share a row or a column.

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[][]) → int

Examples

Example 1

stones = [[0,0],[0,1],[1,0],[1,2],[2,1],[2,2]]return = 5

All six stones form one connected component, so one must remain.

Example 2

stones = [[0,0],[0,2],[1,1],[2,0],[2,2]]return = 3

Four corner stones are connected and the center stone is isolated, so two stones remain.

Constraints

  • 1 <= stones.length <= 1000
  • 0 <= 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

Snap Inc. interview experiences

  • Snap Experienced MLE Onsite Interview Questions: 1 Experience
  • Snap AI Coding Interview, Experienced SWE and MLE: 4 Experiences
  • Snap Experienced MLE Virtual Onsite: 1 Experience
All Snap Inc. interview questionsSee Snap Inc. hiring insights
Saved
class Solution {
    public int removeStones(int[][] stones) {
        // Write your code here
    }
}
Checking account…