TCS digital coding question with solution 2022-2023
TCS Digital Coding problem -1
Problem Description -: Given an array Arr[ ] of N integers and a positive integer K. The task is to cyclically rotate the array clockwise by K.
Note : Keep the first of the array unaltered.
Example 1:
- 5 —Value of N
- {10, 20, 30, 40, 50} —Element of Arr[ ]
- 2 —–Value of K
Output :
40 50 10 20 30
Example 2:
- 4 —Value of N
- {10, 20, 30, 40} —Element of Arr[]
- 1 —–Value of K
Output :
40 10 20 30
Python -
n=int(input())
arr=[int(i) for i in input().split()]
k=int(input())
rfirst=arr[0:n-k]
rsecond=arr[n-k:]
print(rsecond+rfirst)
Comments
Post a Comment
If you have any doubt you ask me in comment section