1 2 3 4 5 6 7 update#
Run a while loop to update the values according to the set. b) Add the answer from previous step 14 to the numerator 1.Store the value of arr in a temporary variable (the value of i denotes the set number).Run a for loop from 0 to the value obtained from GCD.Calculate the GCD(N, d) to divide the array into sets.Perform d%n in order to keep the value of d within the range of the array where d is the number of times the array is rotated and N is the size of the array.Perform this operation d times to rotate the elements to the left by d position.At each iteration, shift the elements by one position to the left circularly (i.e., first element becomes the last).Lastly, copy back the temporary array to the original arrayīelow is the implementation of the above approach :Īpproach 2 (Rotate one by one): This problem can be solved using the below idea:.Now, store 0 to d-1 elements of the original array in the temporary array.
Store the elements from the position d to n-1 in the temporary array.Initialize an integer( k) to keep a track of the current index.Initialize a temporary array( temp) of length same as the original array.=> arr = temp So arr = įollow the steps below to solve the given problem. => Copy the elements of the temp array into the original array. We can access the elements in the array using square brackets. => Store the elements from 2nd index to the last. Copy back the elements of the temp array into the original array.Then store the first d elements of the original array into the temp array.First store the elements from index d to N-1 into the temp array.ISRO CS Syllabus for Scientist/Engineer ExamĪpproach 1 (Using temp array): This problem can be solved using the below idea:Īfter rotating d positions to the left, the first d elements become the last d elements of the array.
ISRO CS Original Papers and Official Keys.GATE CS Original Papers and Official Keys.