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.
Hello , leaving here my soluton with typescript just for compare reasons
functionrotateLeftIndex(index:number,numberOfRotations:number,arr:number[]):number{letrotatedIndex=index-numberOfRotations;if(rotatedIndex<0){rotatedIndex=arr.length+rotatedIndex;// significa que deu a volta}returnrotatedIndex;}functionrotateLeft(d:number,arr:number[]):number[]{consthits=newMap<number,number>()for(leti=0;i<arr.length;i++){constrotatedIndex=rotateLeftIndex(i,d,arr);hits.set(rotatedIndex,arr[rotatedIndex]);conststoredValue=hits.get(i);if(storedValue){arr[rotatedIndex]=storedValue;hits.delete(i);continue;}arr[rotatedIndex]=arr[i];}returnarr}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Left Rotation
You are viewing a single comment's thread. Return to all comments →
Hello , leaving here my soluton with typescript just for compare reasons