educative.io

Question about finding grid number?

@Design_Gurus you mentioned this point “Since our grids would be statically defined (from the fixed grid size), we can easily find the grid number of any location (lat, long) and its neighboring grids.”
how from static size grid find out the grid number of any location?

2 Likes

Imagine Map as matrix and each cell is grid. Now based on user long and lat you can find grid in that matrix and each cell can contain list of location in that.

Will you traverse each and every 20 million grids to find the grid in which user lives? If there is a matrix m*n and i ask you where is my element,you have to check each and every element of matrix.

2 Likes

You can index cells of a matrix sequentially by the following approach:
Imagine you have a R * C matrix, where R is number of rows and C is number of column. Index number of a cell at (r, c) would be (r * C) + c

1 Like

This is not what Rahul asked.

Hi @rahul9 did you find answer for this? searching down from the root and looking for overlaps with each cell is not a feasible option absolutely.


Course: Grokking the System Design Interview - Learn Interactively
Lesson: Designing Yelp or Nearby Friends - Grokking the System Design Interview