This question evaluates understanding of computational geometry and algorithmic optimization, focusing on Manhattan-distance minimization and handling forbidden cells (obstacles) on a 2D integer grid.
Given house coordinates H = {(xi, yi)} and tree coordinates T = {(xj, yj)} on a 2D integer grid, choose a locker location L = (x, y) such that L ∉ T and the sum of Manhattan distances from L to all houses is minimized. Return the minimal total distance and one optimal location. Discuss an efficient algorithm that leverages medians and how to handle cases where the unconstrained median lies on a tree cell.