Education Matters Logo
EDUCATION MATTERS
Back to AssessmentAccenture Round 3: Backend Coding

Backend Coding Practice

Problem solving, array manipulation & algorithm implementation

Question 1 of 1
Q1

Array Rotation

In the kingdom of Aryaland, a magical array is used to unlock the gates of the royal palace. The array has a special property: 1. If the length of the array is even, you must perform a left rotation of only the even-indexed elements. 2. If the length of the array is odd, you must perform a right rotation of only the odd-indexed elements. Your task is to perform the required rotation and return the transformed array.
Note: The array follows 1-based indexing.
Input Specification

input1: An integer value N representing the number of elements in the array.

input2: An integer array A.

Output Specification

Return a transformed array based on the above logic.

Examples & Explanations
Example 1
Input
Input 1: 6
Input 2: (1, 2, 3, 4, 5, 6)
Output
(1, 4, 3, 6, 5, 2)
Explanation: Here, the array is {1,2,3,4,5,6}. The length of the array is even (6), so we have to perform a left rotation of the even-indexed elements, i.e., indices 2, 4 and 6, which are: [2, 4, 6] After a left rotation, they become: [4, 6, 2] The transformed array will be: (1, 4, 3, 6, 5, 2) Hence, (1,4,3,6,5,2) is returned as the output.
Example 2
Input
Input 1: 5
Input 2: (10, 20, 30, 40, 50)
Output
(50, 20, 10, 40, 30)
Explanation: Here, the array is {10,20,30,40,50}. The length of the array is odd (5), so we have to perform a right rotation of the odd-indexed elements, i.e., indices 1, 3 and 5, which are: [10, 30, 50] After a right rotation, they become: [50, 10, 30] The transformed array will be: (50, 20, 10, 40, 30) Hence, (50,20,10,40,30) will be returned as the output.