Google R3 | US

Anonymous User
885
Jun 12, 2025
Jun 12, 2025

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.

F1          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.

Comments (2)