Place a Lamp to Cover the Most Objects
Updated
Problem statement
objects contains unique coordinates in strictly increasing order. A lamp at integer coordinate x illuminates every object whose distance from x is at most radius.
Return an integer lamp coordinate that illuminates the most objects, breaking ties by the smallest coordinate.
Function
bestLampCoordinate(objects: int[], radius: int) → intExamples
Example 1
objects = [-5,3,4,9]radius = 5return = -1The window [-5,4] is covered by lamp coordinate -1 and contains three objects.
Example 2
objects = [7]radius = 2return = 5The smallest lamp coordinate covering the object is five.
Constraints
1 <= objects.length <= 100000-1000000000 <= objects[i] <= 10000000000 <= radius <= 1000000000
More ZipRecruiter Online Assessment questions
- Four-Level Banking System with Scheduled PaymentsOA · Seen Oct 2026
- Count Three-Digit Numbers with Distinct DigitsOA · Seen Oct 2024
- Longest Frequency-Bounded SubarrayOA · Seen Oct 2024
- Minimum Changes to Draw a YOA · Seen Oct 2024
- Apply Binary State OperationsOA · Seen Sep 2024
- Simulate Orchard Rot SpreadOA · Seen Sep 2024
- Compare Odd- and Even-Index SumsOA · Seen Sep 2024
- Coordinate Removals with Column GravityOA · Seen Sep 2024
- Lexicographically Smallest End ReversalOA · Seen Sep 2024
- Recursively Expanded Shell Command CountsOA · Seen Sep 2024
Similar questions at other companies
- Count Subarrays With Product Equal to KSalesforce · OASalesforce interview questions
- Count Belt Sections With K Fruit Pairs (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
- K Smallest SubstringAkuna Capital · OAAkuna Capital interview questions
- Shortest SubstringRippling · OARippling interview questions
- Calculate Difference Value 🍧DoorDash · OADoorDash interview questions
- Maximum Consecutive Sum Within a ThresholdIndeed · OAIndeed interview questions
- Fastest Average Speed over a Rolling KilometerOptiver · OAOptiver interview questions
- Maximum Requests in a Time WindowIBM · OAIBM interview questions
- Maximum Events in a 60-Second WindowMarshall Wace · OAMarshall Wace interview questions
- Subarray Product Less Than KApple · PHONE SCREENApple interview questions