Google R3 | US

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2025-06-12Added By Anonymous
Source: Link

Company: Google
Role: l3, l4
Interview Stage: Onsite
Location: US
Year: unknown

Original Post Content:

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