Given an array Arr of size N, swap the K_{th} element from beginning with K_{th} element from end.
Example 1:
Input:
N = 8, K = 3
Arr[] = {1, 2, 3, 4, 5, 6, 7, 8}
Output: 1 2 6 4 5 3 7 8
Explanation: K_{th} element from beginning is
3 and from end is 6.
Example 2:
Input:
N = 5, K = 2
Arr[] = {5, 3, 6, 1, 2}
Output: 5 1 6 3 2
Explanation: K_{th} element from beginning is
3 and from end is 1.
Your Task:
You don't need to read input or print anything. Your task is to complete the function swapKth() which takes the array of integers arr, n and k as parameters and returns void. You have to modify the array itself.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ K ≤ N ≤ 10^{5}
1 ≤ Arr[i] ≤ 10^{3}

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Starter code: #User function Template for python3

class Solution:

	

	def swapKth(self,arr, n, k):

		# code here

Solutions:
class Solution:

	def swapKth(self, arr, n, k):
		(arr[k - 1], arr[-k]) = (arr[-k], arr[k - 1])
		return arr


class Solution:

	def swapKth(self, arr, n, k):
		start = arr[k - 1]
		end = arr[-k]
		arr[k - 1] = end
		arr[-k] = start


class Solution:

	def swapKth(self, arr, n, k):
		temp = arr[k - 1]
		arr[k - 1] = arr[n - k]
		arr[n - k] = temp


class Solution:

	def swapKth(self, arr, n, k):
		el_from_start = arr[k - 1]
		el_from_end = arr[-k]
		arr[k - 1] = el_from_end
		arr[-k] = el_from_start


class Solution:

	def swapKth(self, arr, n, k):
		temp = 0
		temp = arr[k - 1]
		arr[k - 1] = arr[n - k]
		arr[n - k] = temp
		return arr


class Solution:

	def swapKth(self, arr, n, k):
		temp = None
		temp = arr[k - 1]
		arr[k - 1] = arr[n - k]
		arr[n - k] = temp
		return arr


class Solution:

	def swapKth(self, arr, n, k):
		h = []
		for i in range(n):
			h.append(arr[k - 1])
			h.append(arr[-k])
			arr[k - 1] = h[1]
			arr[-k] = h[0]
		return arr


class Solution:

	def swapKth(self, arr, n, k):
		t = arr[k - 1]
		arr[k - 1] = arr[n - k]
		arr[n - k] = t


class Solution:

	def swapKth(self, arr, n, k):
		a = arr[k - 1]
		b = arr[-k]
		arr[k - 1] = b
		arr[-k] = a
		return arr


class Solution:

	def swapKth(self, arr, n, k):
		n1 = arr[k - 1]
		n2 = arr[-k]
		arr[k - 1] = n2
		arr[-k] = n1


class Solution:

	def swapKth(self, arr, n, k):
		val1 = arr[k - 1]
		val2 = arr[-k]
		arr[k - 1] = val2
		arr[-k] = val1


class Solution:

	def swapKth(self, arr, n, k):
		if k > n:
			return
		else:
			(arr[k - 1], arr[n - k]) = (arr[n - k], arr[k - 1])


class Solution:

	def swapKth(self, arr, n, k):
		first_kth = arr[k - 1]
		last_kth = arr[n - k]
		arr[k - 1] = last_kth
		arr[n - k] = first_kth


class Solution:

	def swapKth(self, arr, n, k):
		a = arr[k - 1]
		arr[k - 1] = arr[n - k]
		arr[n - k] = a


class Solution:

	def swapKth(self, arr, n, k):
		temp_a = arr[k - 1]
		arr[k - 1] = arr[-k]
		arr[-k] = temp_a


class Solution:

	def swapKth(self, arr, n, k):
		num1 = arr[k - 1]
		num2 = arr[n - k]
		arr[k - 1] = num2
		arr[n - k] = num1


class Solution:

	def swapKth(self, arr, n, k):
		if k > n:
			return
		pos1 = k - 1
		pos2 = n - k
		(arr[pos1], arr[pos2]) = (arr[pos2], arr[pos1])
		return


class Solution:

	def swapKth(self, a, n, k):
		(a[k - 1], a[n - k]) = (a[n - k], a[k - 1])
		return a


class Solution:

	def swapKth(self, arr, n, k):
		if k > n or k <= 0:
			return -1
		index1 = k - 1
		index2 = n - k
		(arr[index1], arr[index2]) = (arr[index2], arr[index1])


class Solution:

	def swapKth(self, arr, n, k):
		i = arr[k - 1]
		j = arr[n - k]
		arr[k - 1] = j
		arr[n - k] = i


class Solution:

	def swapKth(self, arr, n, k):
		tal = arr[k - 1]
		arr[k - 1] = arr[n - (k - 1) - 1]
		arr[n - (k - 1) - 1] = tal


class Solution:

	def swapKth(self, arr, n, k):
		temp = arr[k - 1]
		arr[k - 1] = arr[-k]
		arr[-k] = temp
		for i in arr:
			return i


class Solution:

	def swapKth(self, arr, n, k):
		for i in range(n):
			if i == k - 1:
				(arr[i], arr[n - k]) = (arr[n - k], arr[i])
		return arr


class Solution:

	def swapKth(self, arr, n, k):
		first = arr[k - 1]
		second = arr[-k]
		arr[k - 1] = second
		arr[-k] = first
		return arr


class Solution:

	def swapKth(self, arr, n, k):
		first = k - 1
		last = n - k
		temp = arr[first]
		arr[first] = arr[last]
		arr[last] = temp


class Solution:

	def swapKth(self, arr, n, k):
		aux = arr[k - 1]
		arr[k - 1] = arr[n - k]
		arr[n - k] = aux