Online Assessment
Its a hackerrank online assessment test containing 2 coding questions and MCQs
Technical Round 1
Topic: Threads and Synchronization
Question: There are multiple users calling a method reg_cb at different intances of time, as shown below. Simultaneously, there is an event happening. All the user requests that were made during the execution of the event should wait till the event completes and then execute the reg_cb method. Once the event is finished, the user requests to the reg_cb method can be executed immediatly. Implement how to handle the given scenario.
Event in progress
----|---------------|--------------------|-------------------|--------------> timeline
U1: reg_cb(f1) U2: reg_cb(f2) Event completed U3:reg_cb(f3)
(execute f1,f2) (execute f3)Was asked many questions on basic fundamentals like,
Expectations: Concentrate on how you handle different possible scenarios with a valid scenario and explanation. Wrinting code is secondary.
Example squares
// y y y
// ^ ^ ^
// | C | B | D
// | A | A | B
// | OR | OR | ETC
// | | |
// | D | C | A
// | B | D | C
// +----------------->x +----------------->x +----------------->xSolution:
Properties Sufficient to Prove a Square
class Solution {
public boolean isSquare(int[][] arr) {
// (0,0), (1,0), (0,1), and (1,1)
// (0,0), (0,0), (0,0), (0,0)
HashMap<Double, Integer> map = new HashMap<>();
// 4 sides distance
// 2 diagonals distance
// Condition 1: Calculate distance between all points
for(int i=0; i<4; i++) {
for(int j=i+1; j<4; j++) {
double distance = Math.sqrt((arr[i][0] - arr[j][0])^2 + (arr[i][1] - arr[j][1])^2);
if(map.contains(distance)) {
map.get(distance, map.get(distance)+1);
} else {
map.put(distance, 1);
}
}
}
boolean isPossibleSquare = false;
double side = 0;
double diagonal = 0;
for(double key : map.keySet()) {
if(map.get(key) == 4) {
isPossibleSquare = true;
side = key;
} else {
diagonal = key;
}
}
if(!isPossibleSquare) {
return false;
}
// Condition 2 : Verify the Pythagorus theoram
return diagonal == Math.sqrt(2*side*side);
}
}Next Question: Design a function that takes in >= 4 points and returns the number of squares that can be formed (i.e. how many groups of 4 points(x,y coordinates) within the input points form a square)
Expectation: The complexity of the extended question should be O(N^3)