Mark As Completed Discussion

Good afternoon! Here's our prompt for today.

On a given street, there's a bunch of houses and lamps nearby. It looks kind of like the following (H being houses, L being lamps):

SNIPPET
1L H L H H
20 1 2 3 4

We decide to represent this with two arrays: one being the positions of the houses, and the other the positions of the lamps. From the above example, the arrays would be:

SNIPPET
1houses = [1, 3, 4]
2lamps = [0, 2]

With this knowledge, can you find out the minimum radius that the lamps would need to cover in order for every house to get access to light?

Description

Here, the minimum radius would be 2-- the lamp at position 2 needs to cover not only house 3, but up to the house on position 4, so a 2 radius is required.

SNIPPET
1L H L H H
20 1 2 3 4

We can guarantee that there is at least one house and one lamp in every scenario. All lamps cover the same minimum radius.

Constraints

  • Length of the given array <= 100000
  • Values in the array ranges from 0 to 100000
  • Expected time complexity : O(n^2)
  • Expected space complexity : O(1)

Try to solve this here or in Interactive Mode.

How do I practice this challenge?

JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

We'll now take you through what you need to know.

How do I use this guide?

Access all course materials today

The rest of this tutorial's contents are only available for premium members. Please explore your options at the link below.

Returning members can login to stop seeing this.