Given a map of the city and the network range, the task is to determine the minimum number of the tower so that every house is within range of at least one tower. Each tower must be installed on top of an existing house.
Input: range : 1 house : 1 2 3 4 5 Output: 2 Input: range : 2 house : 7 2 4 6 5 9 12 11 Output: 3
All cities can be covered by inserting 2 towers i.e. at house 2 and 4.
All cities can be covered by inserting 3 towers i.e. at house 4, 9 and 12.
- First, sort all the element.
- Count only once and then traverse till its middle house.
- After this again traverse till tower range.
- Again repeat 1, 2, 3 step till all the houses are covered.
Below is the implementation of above approach:
Time Complexity: O(nlogn)
Space Complextity: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Minimum broadcast range required by M towers to reach N houses
- Minimum number of distinct powers of 2 required to express a given binary number
- Minimum number of swaps required to sort an array of first N number
- Minimum number of operations required to reduce N to 1
- Minimum number of changes required to make the given array an AP
- Minimum number of integers required such that each Segment contains at least one of them
- Minimum deletions required such that any number X will occur exactly X times
- Minimum number of swaps required to sort an array
- Minimum Number of Platforms Required for a Railway/Bus Station
- Minimum number of swaps required to sort an array | Set 2
- Minimum number of bottles required to fill K glasses
- Minimum number of days required to complete the work
- Minimum number of swaps required for arranging pairs adjacent to each other
- Minimum number of given operations required to reduce the array to 0 element
- Find out the minimum number of coins required to pay total amount
- Minimum number of colors required to color a Circular Array
- Minimum number of steps required to obtain the given Array by the given operations
- Minimum number of segments required such that each segment has distinct elements
- Minimum number of Circular obstacles required to obstruct the path in a Grid
- Minimum Number of Platforms Required for a Railway/Bus Station | Set 2 (Map based approach)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.