Google R3 | US
Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2025-06-12Added By Anonymous
Source: Link
You are playing a city management simulator that takes place on a 1-dimensional grid X tiles long.
There are N factories present along the line and you know the location of every factory.
Each factory contributes air pollution to the entire grid, decreasing by distance. You want to place your city on the tile with the lowest total air pollution.
1F1 F2 … Fn— — — — — — — — — — — — — - - - - - - - - - - -
1 2 3 … x
Given a city location Cx and a factory on Fx, the pollution contributed by that factory is 1/abs(Cx - Fx).
We have an API to get the pollution.
Write a function that determines the optimal space on which to place the city (lowest pollution).
Answer can only be integer.
X is given.