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
Sort by
recency
|
4926 Discussions
|
Please Login in order to post a comment
fun rotLeft(a: Array, d: Int): Array { val n = a.size val rotatedArray = Array(n) { 0 } for (i in a.indices) { rotatedArray[(i + n - d) % n] = a[i] } return rotatedArray }
Simple java solution:
pyython 3 return a[d:] + a[:d]
public static List rotLeft(List a, int d) { int i,j=0; //d is the start index where an array should start. d=d%a.size(); //create a new array list. List arr= new ArrayList<>(); for(i=d;i
}