Python3 Program to Find Mth element after K Right Rotations of an Array Last Updated : 06 Sep, 2024 Comments Improve Suggest changes Like Article Like Report Python3 # Python3 program to implement # the above approach # Function to return Mth element of # array after k right rotations def getFirstElement(a, N, K, M): # The array comes to original state # after N rotations K %= N # If K is greater or equal to M if (K >= M): # Mth element after k right # rotations is (N-K)+(M-1) th # element of the array index = (N - K) + (M - 1) # Otherwise else: # (M - K - 1) th element # of the array index = (M - K - 1) result = a[index] # Return the result return result # Driver Code if __name__ == "__main__": a = [ 1, 2, 3, 4, 5 ] N = len(a) K , M = 3, 2 print( getFirstElement(a, N, K, M)) # This code is contributed by chitranayal Output4 Time Complexity: O(1) Auxiliary Space: O(1)Please refer complete article on Mth element after K Right Rotations of an Array for more details! Comment More infoAdvertise with us Next Article Python3 Program to Find Mth element after K Right Rotations of an Array K kartik Follow Improve Article Tags : Python rotation array-rearrange Practice Tags : python Similar Reads Javascript Program to Find Mth element after K Right Rotations of an Array Given non-negative integers K, M, and an array arr[ ] consisting of N elements, the task is to find the Mth element of the array after K right rotations. Examples: Input: arr[] = {3, 4, 5, 23}, K = 2, M = 1 Output: 5 Explanation: The array after first right rotation a1[ ] = {23, 3, 4, 5} The array a 8 min read Mth element after K Right Rotations of an Array Given non-negative integers K, M, and an array arr[ ] consisting of N elements, the task is to find the Mth element of the array after K right rotations. Examples: Input: arr[] = {3, 4, 5, 23}, K = 2, M = 1 Output: 5 Explanation: The array after first right rotation a1[ ] = {23, 3, 4, 5} The array a 11 min read Javascript Program to Find the Mth element of the Array after K left rotations Given non-negative integers K, M, and an array arr[] with N elements find the Mth element of the array after K left rotations. Examples: Input: arr[] = {3, 4, 5, 23}, K = 2, M = 1Output: 5Explanation:Â The array after first left rotation a1[ ] = {4, 5, 23, 3}The array after second left rotation a2[ ] 2 min read Find the Mth element of the Array after K left rotations Given non-negative integers K, M, and an array arr[] with N elements find the Mth element of the array after K left rotations. Examples: Input: arr[] = {3, 4, 5, 23}, K = 2, M = 1Output: 5Explanation: The array after first left rotation a1[ ] = {4, 5, 23, 3}The array after second left rotation a2[ ] 5 min read Javascript Program to Find element at given index after a number of rotations An array consisting of N integers is given. There are several Right Circular Rotations of range[L..R] that we perform. After performing these rotations, we need to find element at a given index.Examples : Input : arr[] : {1, 2, 3, 4, 5} ranges[] = { {0, 2}, {0, 3} } index : 1 Output : 3 Explanation 4 min read Like