We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
publicstaticinthackerlandRadioTransmitters(List<int>houses,intrange){houses.Sort();inttransmittersCount=0;inti=0;while(i<houses.Count){transmittersCount++;// Take the first house. intleft=houses[i];intmid=left+range;// Find the first house out of range, put a transmitter 1 house before there.while(i<houses.Count&&houses[i]<=mid){i++;}mid=houses[i-1];intright=mid+range;// Find the first house out of range. Repeat.while(i<houses.Count&&houses[i]<=right){i++;}}returntransmittersCount;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Hackerland Radio Transmitters
You are viewing a single comment's thread. Return to all comments →
C# O(n)