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.
Next Java solution consider avoiding extra rotations.
publicstaticList<Integer>rotateLeft(intd,List<Integer>arr){// Write your code hereif(arr.size()==d)returnarr;//Calculate right rotation and //avoid extra rotations //i.e. d = 16, arr.size() = 5 It's necessary just 1 movement to the rightintrotation=Math.abs(arr.size()-d)%arr.size();System.out.println("rotation:"+rotation);//execute rotationInteger[]rotatedArr=newInteger[arr.size()];intindex=0;for(Integerval:arr){intnewIndex=(index+rotation)%(arr.size());System.out.println("newIndex: "+newIndex);rotatedArr[newIndex]=val;index++;}returnArrays.asList(rotatedArr);}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Left Rotation
You are viewing a single comment's thread. Return to all comments →
Next Java solution consider avoiding extra rotations.