In this blog, I'm going to tell how to Split the array and add the first part to the end using Python.
Example :
Input: arr[] = {1,2,3,4,5,6,7,8}
k = 2
Output : arr[] = {3,4,5,6,7,8,1,2}
Explanation : Split from index 2 and first part {1, 2} add to the end .
def splitArr(arr, n, k):
for i in range(0, k):
x = arr[0]
for j in range(0, n-1):
arr[j] = arr[j + 1]
arr[n-1] = x
# main
arr = [1,2,3,4,5,6,7,8]
n = len(arr)
position = 2
splitArr(arr, n, position)
for i in range(0, n):
print(arr[i], end = ' ')
Tags:
Python Programs