Goldman Sachs Sample Test

pls share the approach of above problem

its not ongoing contest
its sample test

In this problem you need to check only cities that share at least one coordinate.
You can just make two hash maps, one where the key is x and value is the index of the city, and the other have key y, also with index being the value.

Now you just need to sort every array of indexes from lowest coordinate to greatest.

For each query, suppose that you are in position i in the first hash map, and position j in the second one.
You can see that the nearest city that share some x coordinate will be i - 1 or i + 1, the same for the y coordinate, where the nearest will be j - 1 or j + 1.

Just get the minimum of these four, remember to take care with out of bounds indexes, and print the answer.

Tell me if you need help with the code :smiley:
Also put the link to the problem.

where is the link of this contest?

link : https://www.hackerrank.com/tests/b3apmre7hf8/d1f1592209b433c588d8bdc4e8e8e606

@onebit