Stores and Houses
Problem Overview
- For each house on a 1D line, find the nearest store by distance; on ties, pick the smaller store location; duplicates are allowed.
- Input: two integer arrays (stores, houses). Output: array result[i] = location of the closest store to house i. Constraints are unspecified.
- Context: spatial proximity/logistics on a one-dimensional map of locations.
- From Google interviews; a coding interview interview question and problem focused on arrays and distances.
Example
Unlock to view complete problem details
and practice with sample input/output
Was this article helpful?
View Test Cases & Run Code requires membership
Input Variables
Execution Result:
