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.
exactly my point also is the same. no use of rotation further when orginal array and rotated array are same. Could you tell me whether logic will work ?
static int[] circularArrayRotation(int[] a, int k, int[] queries)
{
int[] rotationArray = new int[a.Length];
int[] result = new int[queries.Length];
int rotationStartIndex = (a.Length - k);
int rotationStopIndex = (a.Length - k) - 1;
int index = 0;
while (rotationStartIndex <= a.Length -1)
{
rotationArray[index] = a[rotationStartIndex];
index++;
rotationStartIndex++;
}
rotationStartIndex = index;
index = 0;
while (index <= rotationStopIndex)
{
rotationArray[rotationStartIndex] = a[index];
index++;
rotationStartIndex++;
}
for (int i = 0; i < queries.Length; i++)
{
if (queries[i] < result.Length)
{
result[i] = rotationArray[queries[i]];
}
}
return result;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Circular Array Rotation
You are viewing a single comment's thread. Return to all comments →
exactly my point also is the same. no use of rotation further when orginal array and rotated array are same. Could you tell me whether logic will work ?
static int[] circularArrayRotation(int[] a, int k, int[] queries) { int[] rotationArray = new int[a.Length]; int[] result = new int[queries.Length]; int rotationStartIndex = (a.Length - k); int rotationStopIndex = (a.Length - k) - 1; int index = 0; while (rotationStartIndex <= a.Length -1) { rotationArray[index] = a[rotationStartIndex]; index++; rotationStartIndex++; } rotationStartIndex = index; index = 0; while (index <= rotationStopIndex) { rotationArray[rotationStartIndex] = a[index]; index++; rotationStartIndex++; }