CHIME SDE Interview
Anonymous User
997

I had 2 rounds.
1 was manager round where it would be behavioural, challenges kind of questions with rapid fire about few distributed systems terms.
2nd was code signal round. Prepare well tag question. they change it little bit

Given a list of mines represented as 3-tuples (x, y, radius of explosion) - write a program which takes this input and returns the most destructive mine.
Input: [][]float64{{-3,3,3}, {-1,2,3}, {1,8,4}, {3,1,2}, {-2,-2,3.5}, {1,1,2}, {-1,1,1}, {3,3,1}}
Expected Output: []float64{-2,-2,3.5}

my solution war pretty much close
double[] solution(double[][] minesMatrix) {

//null cases
if(minesMatrix.length == 0 ||minesMatrix == null){
return new double [] {0.0,0.0,0.0};
}

double max = 0.0;
double finalAns = 0.0;
double x =0.0, y=0.0, z=0.0;
for(int i=0; i< minesMatrix.length;i++){
double [] cooridante = minesMatrix[i];
x = cooridante[0];
y = cooridante[1];
z = cooridante[2];
max = Math.max(max, bfs(minesMatrix, i));
finalAns = Math.max(max, finalAns);

}

return new double[] {x,y,z};
}

public double bfs(double [][] minesMatrix, int index){

Queue queue = new LinkedList<>();
boolean [] seen = new boolean[minesMatrix.length];
queue.offer(index);
seen[index] = true;
double count = 1.0;
while(!queue.isEmpty()){
int poll = queue.poll();
for(int j=0;j<minesMatrix.length;j++){
if(!seen[j]){
if(isInRange(minesMatrix[poll], minesMatrix[j])){
count++;
seen[j] = true;
queue.offer(j);
}

    }  
}  

}
return count;
}

public boolean isInRange(double [] point1, double[] point2){

double d1 =point1[0] - point2[0];
double d2 = point1[1] - point2[1];

double dist = d1 d1 + d2 d2;
double radius = point1[2];

return dist < radius* radius;
}

Comments (6)