Maximum Number of Visible Points
Real-world version: Aiming the Yard CameraThe statement here is our own: the same inputs, outputs and technique.
A stocktake camera sits on a fixed mast in a container yard. The yard is mapped on integer grid coordinates: the mast stands at mast = [mx, my], and tags lists the coordinates of the radio tags stuck to the containers, so tags[i] = [xi, yi]. Several tags may sit at the same coordinates, and a tag may sit at the mast's own coordinates.
The camera can be swivelled to any bearing but its lens is fixed: it takes in a wedge that is exactly sweep degrees wide, with the mast at the wedge's tip. Aim it once and it reads every tag that falls inside that wedge, edges included; a tag exactly on either edge is read. Containers do not hide one another, so distance and stacking are irrelevant. A tag lying at the mast's own coordinates has no bearing at all and is read no matter where the camera points.
Return the largest number of tags a single aim can read.
Examples
Example 1
- Input
- tags = [[6, 4], [7, 4], [8, 5]], sweep = 45, mast = [5, 4]
- Output
- 3
Pointing the camera due east takes in all three tags at once, so nothing is left out of the reading.
Example 2
- Input
- tags = [[5, 4], [5, 4], [2, 8], [8, 8]], sweep = 0, mast = [5, 4]
- Output
- 3
Two tags share the mast's coordinates and are read on any aim. The wedge has no width at all, so of the two remaining tags only one can be lined up.
Example 3
- Input
- tags = [[44, 51], [44, 49], [46, 52]], sweep = 40, mast = [50, 50]
- Output
- 3
One aim towards the west, tilted slightly north, brings all three tags inside the wedge together.
Constraints
- 1 <= tags.length <= 10^5
- tags[i].length == 2
- mast.length == 2
- 0 <= sweep < 360
- 0 <= mx, my, xi, yi <= 100
- The answer is a plain tag count, so no rounding is involved.
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def tags_in_view(tags: list[list[int]], sweep: int, mast: list[int]) -> int:public int tagsInView(int[][] tags, int sweep, int[] mast)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 8 test cases: 8 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- K Closest Points to OriginReal-world version: Nearest Survey StakesMedium
- Minimum Area RectangleReal-world version: The Smallest Upright FrameMedium
- Maximize the Distance Between Points on a SquareReal-world version: Spreading Marks Round a Square FenceHard
- Maximum Product of Three NumbersReal-world version: Largest Triple DriftEasy