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>circularArrayRotation(List<Integer>a,intk,List<Integer>queries){// Write your code hereintn=a.size();k%=n;reverse(a,0,n-1);reverse(a,0,k-1);reverse(a,k,n-1);List<Integer>result=newArrayList<>();for(inti=0;i<queries.size();i++){result.add(a.get(queries.get(i)));}returnresult;}privatestaticvoidreverse(List<Integer>a,intstart,intend){while(start<end){inttemp=a.get(start);a.set(start,a.get(end));a.set(end,temp);start++;end--;}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Circular Array Rotation
You are viewing a single comment's thread. Return to all comments →
java solution