Algorithm · C3.ai · Medium
You are given a grid made up of 0s and 1s. Each cell containing 1 marks the home of one person. Choose a meeting point in the grid such that the combined Manhattan distance from every home to that point is as small as possible, and return this smallest possible total. The Manhattan distance between cells (r1, c1) and (r2, c2) is $$ r1 - r2 + c1 - c2 $$. Constraints: The grid is binary: every cell is either 0 or 1. Each 1 represents exactly one person's home. The source does…