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.
Java8 using TreeSet whose Keys traversing should take BigO(1)
while ArrayList.contains() checks take BigO(n)
publicstaticinthackerlandRadioTransmitters(List<Integer>x,intk){// Write your code hereTreeSet<Integer>set=newTreeSet<>(x);intcount=0;Integerkey=set.first();while(key!=null){//find furthest radio station that //can cover current keyIntegerradioKey=set.floor(key+k);//set new key outside of current radio rangekey=set.ceiling(radioKey+k+1);count++;}returncount;}
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 →
Java8 using TreeSet whose Keys traversing should take BigO(1) while ArrayList.contains() checks take BigO(n)