employer cover photo
employer logo

Pregunta de entrevista de VMware

Rotate elements in an array to right k times.

Respuestas de entrevistas

Anónimo

23 jun 2015

#define element int element a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; int rotate_a(int k) { int i, bufsize, a_size; element *buf; a_size = sizeof(a); bufsize = sizeof(element) * k; if (!(buf = malloc(bufsize))) return -1; memcpy(buf, (void *)a + a_size - bufsize, bufsize); memmove((void *)a + bufsize, a, a_size - bufsize); memcpy(a, buf, bufsize); return 1; }

Anónimo

23 jun 2015

private static int[] flipArrayRight(int[] array, int times) { for (int i = 0; i 0; k--) { array[k] = array[k - 1]; } array[0] = last; } return array; }

Anónimo

9 ene 2017

public static Array rotateArrayByNFromRight(int[] ArrayToBeRotated, int N) { int ArrayLength = ArrayToBeRotated.Length; if ((N > 0) && (N <= ArrayLength)) { Array.Reverse(ArrayToBeRotated, 0, ArrayLength - N); Array.Reverse(ArrayToBeRotated, ArrayLength - N, N); Array.Reverse(ArrayToBeRotated); } else { Console.WriteLine("invalid"); } return ArrayToBeRotated; }

Anónimo

23 ene 2017

x = [1,2,3,4,5] #Given list or array. k = len(x) y = 3 def rot (x,y): for i in range(y): temp = x[0] del x[0] x.insert(k-1,temp) print x rot(x,y)