Provided an array Arr of N integers, you need to reverse a subarray of that array. The range of this subarray is given by L and R.
Example 1:
Input:
N = 7
Arr[] = {1, 2, 3, 4, 5, 6, 7}
L = 2, R = 4
Output:
1 4 3 2 5 6 7
Explanation: After reversing the elements 
in range 2 to 4 (2, 3, 4), 
modified array is 1, 4, 3, 2, 5, 6, 7.
Example 2:
Input:
N = 4
Arr[] = {1, 6, 7, 4}
L = 1, R = 4
Output:
4 7 6 1
Explanation: After reversing the elements
in range 1 to 4 (1, 6, 7, 4),
modified array is 4, 7, 6, 1.
Your Task:  
You don't need to read input or print anything. Your task is to complete the function reverseSubArray() which takes the array of integers arr, n, l and r as parameters and returns void. You need to change the array itself.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ N ≤ 10^{7}
1 ≤ Arr[i] ≤ 10^{6}
1 ≤ L ≤ R ≤ N

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Starter code: #User function Template for python3
class Solution:

	def reverseSubArray(self,arr, n, l, r):
		# code here

Solutions:
class Solution:

	def reverseSubArray(self, arr, n, l, r):
		arr[l - 1:r] = arr[l - 1:r][::-1]


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		a = arr[l - 1:r]
		a.reverse()
		m = 0
		for k in range(l - 1, r):
			arr[k] = a[m]
			m = m + 1
		return arr


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		start = l - 1
		end = r - 1
		while start < end:
			(arr[start], arr[end]) = (arr[end], arr[start])
			start += 1
			end -= 1


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		a = arr[:l - 1]
		b = arr[l - 1:r]
		c = arr[r:]
		arr[:] = a + b[::-1] + c
		return arr


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		left = l - 1
		right = r - 1
		while left < right:
			(arr[left], arr[right]) = (arr[right], arr[left])
			left += 1
			right -= 1
		return arr


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		l1 = arr[:l - 1]
		l2 = arr[l - 1:r]
		l3 = arr[r:]
		arr[:] = l1 + l2[::-1] + l3
		return arr


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		s = l - 1
		e = r - 1
		while s < e:
			(arr[s], arr[e]) = (arr[e], arr[s])
			s += 1
			e -= 1


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		arr[l - 1:r] = reversed(arr[l - 1:r])
		return arr


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		k = arr[l - 1:r]
		k = k[::-1]
		t = 0
		for i in range(l - 1, r):
			arr[i] = k[t]
			t += 1


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		i = l - 1
		j = r - 1
		while i < j:
			temp = arr[i]
			arr[i] = arr[j]
			arr[j] = temp
			i += 1
			j -= 1
		return arr


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		if l > 1:
			arr[l - 1:r] = arr[r - 1:l - 2:-1]
		else:
			arr[l - 1:r] = arr[r - 1::-1]


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		arr1 = []
		fir = arr[l - 2]
		arr1[:] = arr[l - 1:r][::-1]
		arr[l - 1:r] = arr1[:]
		return arr


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		l = l - 1
		r = r - 1
		while l < r:
			temp = arr[l]
			arr[l] = arr[r]
			arr[r] = temp
			l += 1
			r -= 1


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		v = []
		j = 0
		for i in range(l - 1, r):
			v.append(arr[i])
		v.reverse()
		for i in range(l - 1, r):
			arr[i] = v[j]
			j += 1
		return arr


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		arr1 = arr[l - 1:r]
		arr1.reverse()
		arr[l - 1:r] = arr1
		return arr


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		y = arr[l - 1:r]
		arr[l - 1:r] = reversed(y)


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		first = arr[:l - 1]
		mid = arr[l - 1:r]
		last = arr[r:]
		mid.reverse()
		arr[:] = first + mid + last


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		l = l - 1
		r = r - 1
		a = arr[:l] + arr[l:r + 1][::-1] + arr[r + 1:]
		for i in range(0, len(a)):
			arr[i] = a[i]
		return arr


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		l -= 1
		rev_sub_array = [x for x in reversed(arr[l:r])]
		arr[l:r] = rev_sub_array


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		a = arr.copy()
		l2 = arr[l - 1:r]
		l2.reverse()
		del arr[l - 1:r]
		for i in l2:
			arr.insert(l - 1, i)
			l += 1
		return arr


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		l -= 1
		sub = arr[l:r][::-1]
		arr[l:r] = sub
		return arr


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		s = arr[l - 1:r]
		s = s[::-1]
		j = 0
		for i in range(l - 1, r):
			arr[i] = s[j]
			j += 1


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		arr_middle = arr[l - 1:r]
		arr_middle.reverse()
		for i in range(l - 1, r):
			arr[i] = arr_middle.pop(0)


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		p1 = l - 1
		p2 = r - 1
		while p1 < p2:
			temp = arr[p1]
			arr[p1] = arr[p2]
			arr[p2] = temp
			p1 = p1 + 1
			p2 = p2 - 1
		return arr


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		aa = arr[:l - 1]
		bb = arr[l - 1:r][::-1]
		cc = arr[r:]
		abc = aa + bb + cc
		arr[:] = abc[:]


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		x = arr[l - 1:r]
		x.reverse()
		d = arr[:l - 1]
		e = arr[r:]
		arr.clear()
		arr.extend(d)
		arr.extend(x)
		arr.extend(e)
		return arr


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		l1 = arr[l - 1:r]
		l1.reverse()
		a = arr[:l - 1]
		b = arr[r:]
		arr.clear()
		arr.extend(a)
		arr.extend(l1)
		arr.extend(b)
		return arr


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		a = arr[l - 1:r]
		a.reverse()
		x = arr[:l - 1]
		b = arr[r:]
		arr.clear()
		arr.extend(x)
		arr.extend(a)
		arr.extend(b)


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		p = []
		z = 0
		for i in range(r - 1, l - 2, -1):
			p.append(arr[i])
		for i in range(l - 1, r):
			arr[i] = p[z]
			z += 1


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		k = arr[:l - 1]
		arr2 = arr[l - 1:r]
		arr2.reverse()
		k = k + arr2 + arr[r:]
		for i in range(n):
			arr[i] = k[i]


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		a = arr[l - 1:r]
		ans = arr[:l - 1] + a[::-1] + arr[r:]
		arr.clear()
		for i in ans:
			arr.append(i)
		return ans


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		ar1 = arr[0:l - 1]
		ar2 = arr[l - 1:r]
		ar3 = arr[r:]
		ar2 = ar2[::-1]
		i = 0
		for e in ar1:
			arr[i] = e
			i = i + 1
		for e in ar2:
			arr[i] = e
			i = i + 1
		for e in ar3:
			arr[i] = e
			i = i + 1
		return arr


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		if l == r:
			return arr
		while l < r:
			(arr[l - 1], arr[r - 1]) = (arr[r - 1], arr[l - 1])
			l += 1
			r -= 1
		return arr


class Solution:

	def reverseSubArray(self, arr, n, l, r):
		if l > 0 and r <= n:
			start = l - 1
			end = r - 1
			while start < end:
				(arr[start], arr[end]) = (arr[end], arr[start])
				start += 1
				end -= 1