- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Program to find ith element by rotating k times to right

Suppose we have an array nums, and a value k and another value i. We have to find the element at index i after rotating elements of nums, k number of times to the right.

So, if the input is like nums = [2,7,9,8,10] k = 3 i = 2, then the output will be 10 because after 3rd rotation array will be [9,8,10,2,7], so now the ith element will be nums[2] = 10.

To solve this, we will follow these steps −

- for r in range 0 to k, do
- delete last element from nums and insert that deleted element into nums at position 0

- return nums[i]

## Example

Let us see the following implementation to get better understanding

def solve(nums, k, i): for r in range(k): nums.insert(0, nums.pop()) return nums[i] nums = [2,7,9,8,10] k = 3 i = 2 print(solve(nums, k, i))

## Input

[2,7,9,8,10] , 3, 2

## Output

10

- Related Questions & Answers
- Program to find replicated list by replicating each element n times
- Program to find circular greater element to the right in Python
- Program to count how many blocks are covered k times by walking in Python
- Program to find minimum possible sum by changing 0s to 1s k times from a list of numbers in Python?
- Python Program to Find Element Occurring Odd Number of Times in a List
- Program to find modulus of a number by concatenating n times in Python
- Find the K-th minimum element from an array concatenated M times in C++
- Program to find elements from list which have occurred at least k times in Python
- Program to find k where given matrix has k by k square of same value in C++
- C# program to find K’th smallest element in a 2D array
- Python program to find k'th smallest element in a 2D array
- Python program to right rotate a list by n
- Program to find maximum sum by removing K numbers from ends in python
- Program to find how many ways we can climb stairs (maximum steps at most k times) in Python
- Program to find maximum sum by performing at most k negate operations in Python

Advertisements