AlgoMaster Logo
AlgoMasterFind Adjacent Geohash Cellshard

Find Adjacent Geohash Cells

hard

Geohash cells form a rectangular grid at every precision. Nearby-search systems often begin with a cell and its eight compass neighbors before applying exact distance filtering.

Design GeohashNeighborFinder.neighbors(geohash). Use alphabet 0123456789bcdefghjkmnpqrstuvwxyz. Each character contributes five high-to-low bits, interleaved longitude first, then latitude. Interpret the longitude and latitude bit streams as unsigned grid indices.

Return neighbors in order N, NE, E, SE, S, SW, W, NW, at the same precision. Longitude wraps across the antimeridian. Latitude does not wrap: when a movement crosses a pole, return "" in that direction. Use integer grid operations rather than decoded floating-point centers.

Example 1:
Example 2:

Constraints

  • 1 <= geohash.length <= 12
  • Every character belongs to the standard lowercase geohash alphabet.
Hints

Loading...
CallReturns
new GeohashNeighborFinder()null
neighbors("u4pruydqqvj")["u4pruydqqvm","u4pruydqqvq","u4pruydqqvn","u4pruydqquy","u4pruydqquv","u4pruydqquu","u4pruydqqvh","u4pruydqqvk"]

All eight cells preserve the eleven-character precision and follow compass order.

Run checks these cases. Submit also runs a larger hidden set.