Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Maximum Walls Destroyed by Robots

XPChallenge Points: 30
levelLevel: Hard

You are given the positions of robots and walls along an infinite one-dimensional line.
Each robot has one bullet that can be fired either left or right, but only up to a limited range defined by distance[i].

  • A bullet destroys every wall it touches within its allowed range.

  • However, bullets cannot pass through other robots. If a bullet encounters another robot before hitting a wall, it stops immediately.

  • Walls and robots may exist at the same position, and in such a case, the wall can still be destroyed.

Your task is to determine the maximum number of distinct walls that can be destroyed if robots choose their best firing directions.

Example 1:

Input: robots = [3], distance = [10], walls = [3,8,15]

Output: 2

Explanation:

Robot at position 3 can fire right covering up to position 13. Walls at positions 3 and 8 are destroyed; wall at 15 is out of range.

Example 2:

Input: robots = [5,12], distance = [3,4], walls = [2,9,12,15]

Output: 3

Explanation:

Robot at 5 fires left → destroys wall at 2. Robot at 12 fires right → destroys walls at 12 and 15. Total destroyed = 3.

Example 3:

Input: robots = [4,7,9], distance = [2,5,1], walls = [3,6,8,10]

Output: 2

Explanation:

Any shot fired will always hit another robot before reaching most walls. Only walls at 3 and 10 can be destroyed individually.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result