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.
- Arrays: Left Rotation
- Discussions
Arrays: Left Rotation
Arrays: Left Rotation
+ 0 comments what went wrong with this code? function rotLeft(a, d) { // Write your code here
let sArr = a.slice(0,d); let rArr = a.slice(d) let rotArr =rArr.concat(sArr) let str = ""; rotArr.forEach(function(element){ str += element + " "; }) console.log(str)
}
+ 0 comments C#
int item = 0; for (int i = 0; i < d; i++) { item = a[0]; a.RemoveAt(0); a.Add(item); } return a;
+ 0 comments JavaScript
let newArr = a.slice(d) newArr = [...newArr,...a.slice(0,d)] return newArr
+ 0 comments Javascript
let arr1 = a.slice(0,d); let arr2 = a.slice(d, a.length); arr2.push(...arr1) return arr2
+ 0 comments C++
vector<int> rotLeft(vector<int> a, int d) { vector<int> arr; int siz = a.size(), idx; for(int i = 0; i < siz; i++){ idx = (i + d) % siz; arr.insert(arr.end(), a[idx]); } return arr; }
Load more conversations
Sort 4818 Discussions, By:
Please Login in order to post a comment