Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
547 views
in Online Assessments by Expert (34,270 points) | 547 views

1 Answer

0 like 0 dislike

We were given N coordinates of the form (X, Y) where X is the x-coordinate and Y is the y-coordinate of the location. There are Q queries of three types and their first element represents the type of query.
For Ex: 1 2 4. means query of type-1.
Type1: Type-1 is of the form: (type, lower_range_of_x, upper_range_of_x). We have to find the output of the minimum distance possible from all the coordinates satisfying the above range criteria.
Type2: Type-2 is of the form: (type, lower_range_of_y, upper_range_of_y). We also have to find the output of the minimum distance possible from all the coordinates lying in the range.
Type3: Type-3 is of the form: (type, lower_range_of_x, upper_range_of_x, lower_range_of_y, upper_range_of_y). We also have to find the output of the minimum distance possible satisfying the above range criteria for both x and y coordinates.
We have to return a vector which contains the answers of the queries.
I tried to solve it using segment trees, but I am not sure how to do that. Do we need to create multiple segment trees?
In JIO's OA, we were given two questions in 45 mintues and another one was medium, however, the problem statements were huge, thus making it difficult to understand quickly.

by Expert (34,270 points)