Cyber Beacon Detection
Updated
Problem statement
A network is modeled as every integer-coordinate node inside an axis-aligned rectangle whose bottom-left corner is (x1, y1) and top-right corner is (x2, y2). Both rectangle boundaries are inclusive.
A beacon centered at (beaconX, beaconY) completely illuminates a node when the node's Euclidean distance from the beacon is at most radius.
Return the number of network nodes that are completely illuminated.
Equivalently, count the integer pairs (x, y) that satisfy both rectangle bounds and (x - beaconX)^2 + (y - beaconY)^2 <= radius^2.
Function
countIlluminatedNodes(x1: int, y1: int, x2: int, y2: int, beaconX: int, beaconY: int, radius: int) → longExamples
Example 1
x1 = -2y1 = -2x2 = 2y2 = 2beaconX = 0beaconY = 0radius = 1return = 5The illuminated nodes are the center and its four axis-adjacent neighbors.
Example 2
x1 = 0y1 = 0x2 = 2y2 = 2beaconX = 0beaconY = 0radius = 2return = 6The six points are (0,0), (0,1), (0,2), (1,0), (1,1), and (2,0).
Example 3
x1 = 5y1 = 5x2 = 7y2 = 7beaconX = 0beaconY = 0radius = 2return = 0The rectangle does not intersect the illuminated circle.
Example 4
x1 = 0y1 = 0x2 = 1y2 = 1beaconX = 0beaconY = -7radius = 8return = 3The rectangle has four nodes. The nodes (0,0), (1,0) and (0,1) are at distances 7, about 7.07 and exactly 8 from the beacon, so they are lit. Node (1,1) is about 8.06 away, just outside the radius, so the answer is 3.
Constraints
-10^9 <= x1 <= x2 <= 10^9-10^9 <= y1 <= y2 <= 10^9-10^9 <= beaconX, beaconY <= 10^90 <= radius <= 10^9x2 - x1 <= 2 * 10^5
More Rippling Online Assessment questions
- Most Segments That Sort the ArrayOA · Seen Nov 2026
- Palindromic Paths to the RootOA · Seen Nov 2026
- Server InvestmentOA · Seen Nov 2026
- Corporate Card Expense RulesOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- REST API: Highest International StudentsOA · Seen Sep 2026
- Token ValidationOA · Seen Sep 2026
- Consistent LogsOA · Seen Sep 2026
- Costliest ChocolateOA · Seen Sep 2026
- Server ManagementOA · Seen Sep 2026
- IPv4 Address ClassificationOA · Seen Aug 2026
Similar questions at other companies
- Count Pairs of Overlapping SquaresCapital One · OACapital One interview questions
- Server Upgrade PlanningWells Fargo · OAWells Fargo interview questions
- Perfect Squares Matching a PatternNielsen · OA
- Maximum Alloy Production Within BudgetMicrosoft · OAMicrosoft interview questions
- Linear InterpolatorTwo Sigma · OATwo Sigma interview questions
- Rock JumpingIMC Trading · OAIMC Trading interview questions
- Count Lucky Numbers in a RangeTarget · OA
- Souvenir Shop PurchasesAmazon · OA
- TikTok Video Relevance AdjustmentTikTok · OATikTok interview questions
- Paint the CeilingSnowflake · OASnowflake interview questions