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 integers required such that each Segment contains at least one of them
- Minimum sum subsequence such that at least one of every four consecutive elements is picked
- Largest area in a grid unbounded by towers
- Count pairs (p, q) such that p occurs in array at least q times and q occurs at least p times
- Longest Subsequence with at least one common digit in every element
- Find minimum sum such that one of every three consecutive elements is taken
- Find K for every Array element such that at least K prefixes are ≥ K
- Longest subarray such that adjacent elements have at least one common digit | Set 1
- Count pairs in an array such that at least one element is prime
- Longest subsequence such that adjacent elements have at least one common digit
- Longest subarray such that adjacent elements have at least one common digit | Set - 2
- Minimum increments by index value required to obtain at least two equal Array elements
- Minimum number N such that total set bits of all numbers from 1 to N is at-least X
- Minimum sub-array such that number of 1's in concatenation of binary representation of its elements is at least K
- Maximum sum in an array such that every element has exactly one adjacent element to it
- Count of minimum reductions required to get the required sum K
- [TopTalent.in] Interview with Sujeet Gholap, placed in Microsoft, Google, Samsung, Goldman Sachs & Tower Research
- Minimize cost of operation to equalize tower heights
- Minimum number of segments required such that each segment has distinct elements
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.