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.
- Prepare
- Data Structures
- Arrays
- Left Rotation
- Discussions
Left Rotation
Left Rotation
+ 0 comments My Javascript Code:
function rotateLeft(d, arr) { // Write your code here let res=[...arr] for(let i=0;i<d;i++){ res.push(res.shift()) } return res }
+ 0 comments public static List<Integer> rotateLeft(int d, List<Integer> arr) { // Write your code here int len = arr.size(); List<Integer> newArr = new ArrayList<>(); int i = d; int j = 0; while(i < len){ newArr.add(arr.get(i)); i++; } while(j < d){ newArr.add(arr.get(j)); j++; } return newArr; }
+ 0 comments Javascript
function rotateLeft(d, arr) { for(let i=0;i<d;i++){ arr.push(arr.shift()) } return arr }
+ 0 comments c++
int i=0; while(i<d){ int temp=arr[0]; arr.erase(arr.begin()); arr.push_back(temp); i++;}
+ 0 comments public static List rotateLeft(int d, List arr) { int i=0; while(i
return arr; }**``````````**
Load more conversations
Sort 3208 Discussions, By:
Please Login in order to post a comment