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.
publicstaticList<Integer>waiter(List<Integer>number,intq){// Write your code hereList<Integer>prime=getPrime(q);List<Integer>num=newArrayList<>();for(intp:prime){for(inti=0;i<number.size();i++){if(number.get(i)%p==0){num.add(number.get(i));number.remove(i);i--;}}Collections.reverse(number);}Collections.reverse(number);num.addAll(number);returnnum;}publicstaticList<Integer>getPrime(intnumber){List<Integer>prime=newArrayList<>();intp=2;while(prime.size()<number){booleanflag=false;for(inti=2;i<=Math.sqrt(p);i++){if(p%i==0){flag=!flag;break;}}if(!flag){prime.add(p);}p++;}returnprime;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Waiter
You are viewing a single comment's thread. Return to all comments →
JAVA