Aug 29, 2017 · 1 min read
Solution for HackerRank Problem in C# : Hackerland Radio Transmitters
Problem statement can be found here : https://www.hackerrank.com/challenges/hackerland-radio-transmitters
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution {static void Main(String[] args) {
string[] tokens_n = Console.ReadLine().Split(‘ ‘);
int noOfHouse = Convert.ToInt32(tokens_n[0]);
int range = Convert.ToInt32(tokens_n[1]);
string[] x_temp = Console.ReadLine().Split(‘ ‘);
int[] x = Array.ConvertAll(x_temp,Int32.Parse);
noOfHouse = x.Max();
int towerCount = 1;
int maxRange = range * 2 + 1;
int noOfHousesLeft = noOfHouse — maxRange;
while (noOfHousesLeft > maxRange)
{
towerCount++;
noOfHousesLeft = noOfHousesLeft — maxRange;
}
if (noOfHousesLeft > 0)
towerCount++;
Console.WriteLine(towerCount);
}
}
