There is a given an array and split it from a specified position, and move the first part of array add to the end.

Examples:
Input : arr[] = {12, 10, 5, 6, 52, 36}
k = 2
Output : arr[] = {5, 6, 52, 36, 12, 10}
Explanation : Split from index 2 and first
part {12, 10} add to the end .
Input : arr[] = {3, 1, 2}
k = 1
Output : arr[] = {1, 2, 3}
Explanation : Split from index 1 and first
part add to the end.
# Python program to split array and move first # part to 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 = [12, 10, 5, 6, 52, 36] n = len(arr) position = 2 splitArr(arr, n, position) for i in range(0, n): print(arr[i], end = ' ') # Code Contributed by Mohit Gupta_OMG <(0_o)> |
chevron_right
filter_none
Output:
5 6 52 36 12 10
Please refer complete article on Split the array and add the first part to the end for more details!
Another Solution :
# Python program to split array and move first # part to end. def splitArr(a, n, k): b = a[:k] return (a[k::]+b[::]) # main arr = [12, 10, 5, 6, 52, 36] n = len(arr) position = 2arr = splitArr(arr, n, position) for i in range(0, n): print(arr[i], end = ' ') |
chevron_right
filter_none
Output:
5 6 52 36 12 10
Recommended Posts:
- Python - Sort given list of strings by part the numeric part of string
- Python program to split and join a string
- Python program to split the string and convert it to dictionary
- Python program to find start and end indices of all Words in a String
- Python program to split a string by the given list of strings
- Python Program for Minimum number of jumps to reach end
- Python | Check if substring is part of List of Strings
- Python | Sort given list of strings by part of string
- Python - Test if element is part of dictionary
- Python - Substitute prefix part of List
- Python | Split dictionary keys and values into separate lists
- Python | Split strings and digits from string list
- Python program to add two numbers
- Python program to add two Octal numbers
- Python Program to add two hexadecimal numbers
- Python program to add two binary numbers
- Python - Group Similar Start and End character words
- Python | Split given string into equal halves
- Python | Custom list split
- Python | Split dictionary of lists to list of dictionaries
Improved By : ishagup14

