As we know, Ishaan has a love for chocolates. He has bought a huge chocolate bar that contains N chocolate squares. Each of the squares has a tastiness level which is denoted by an array A[].
Ishaan can eat the first or the last square of the chocolate at once. Ishaan has a sister who loves chocolates too and she demands the last chocolate square. Now, Ishaan being greedy eats the more tasty square first. 
Determine the tastiness level of the square which his sister gets.
Example 1:
Input : arr[ ] = {5, 3, 1, 6, 9}
Output : 1
Explanation:
Initially: 5 3 1 6 9
In first step: 5 3 1 6
In Second step: 5 3 1
In Third step: 3 1
In Fourth step: 1
Return 1
Example 2:
Input : arr[ ] = {5, 9, 2, 6} 
Output :  2
Your Task:
This is a function problem. The input is already taken care of by the driver code. You only need to complete the function chocolates() that takes an array (arr), sizeOfArray (n) and return the tastiness level of the square which his sister gets. The driver code takes care of the printing.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).
 
Constraints : 
1 ≤ N ≤ 10^{5}
1 ≤ A[i] ≤ 10^{9}

Difficulty: EASY
Tags: Data structures

Amortized analysis

Greedy algorithms
Skill types: Amortized analysis

Data structures

Greedy algorithms
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).

Starter code:
from typing import List





class Solution:

    def chocolates(self, n : int, arr : List[int]) -> int:

        # code here

        



Solutions:
from typing import List

class Solution:

	def chocolates(self, n: int, arr: List[int]) -> int:
		return min(arr)


from typing import List

class Solution:

	def chocolates(self, n: int, arr: List[int]) -> int:
		arr.sort()
		return arr[0]


from typing import List

class Solution:

	def chocolates(self, n: int, arr: List[int]) -> int:
		for i in range(0, n):
			if i == n - 1:
				return arr[0]
			elif arr[0] > arr[-1]:
				arr.pop(0)
			else:
				arr.pop(-1)


from typing import List

class Solution:

	def chocolates(self, n: int, arr: List[int]) -> int:
		(i, j) = (0, n - 1)
		while i < j:
			if arr[i] > arr[j]:
				i += 1
			else:
				j -= 1
		return arr[i]


from typing import List

class Solution:

	def chocolates(self, n: int, arr: List[int]) -> int:
		start = 0
		end = n - 1
		while start < end:
			if arr[start] > arr[end]:
				start += 1
			else:
				end -= 1
		return arr[start]


from typing import List

class Solution:

	def chocolates(self, n: int, arr: List[int]) -> int:
		arr.sort(reverse=True)
		return arr[-1]


from typing import List
import math

class Solution:

	def chocolates(self, n: int, arr: List[int]) -> int:
		if n == 1:
			return arr[0]
		mini = math.inf
		(i, j) = (0, n - 1)
		while i < j:
			if arr[i] > arr[j]:
				mini = min(mini, arr[j])
				i += 1
			elif arr[i] < arr[j]:
				mini = min(mini, arr[i])
				j -= 1
			else:
				mini = min(mini, arr[i])
				i += 1
				j -= 1
		return mini


from typing import List

class Solution:

	def chocolates(self, n: int, arr: List[int]) -> int:
		for i in range(n):
			if len(arr) == 1:
				break
			a = arr[0]
			b = arr[-1]
			if b >= a:
				arr.pop()
			if a > b:
				arr.pop(0)
		return arr[0]

	def sols(self, n, arr):
		pass


from typing import List

class Solution:

	def chocolates(self, n: int, arr: List[int]) -> int:
		min = arr[0]
		for i in range(1, n):
			if arr[i] < min:
				min = arr[i]
		return min


from typing import List

class Solution:

	def chocolates(self, n: int, arr: List[int]) -> int:
		a = sorted(arr)
		return a[0]


from typing import List

class Solution:

	def chocolates(self, n: int, arr: List[int]) -> int:
		my_arr = sorted(arr)
		first_element = my_arr[0]
		return first_element


from typing import List

class Solution:

	def chocolates(self, n: int, arr: List[int]) -> int:
		l = 0
		h = n - 1
		while l < h and n > 1:
			if arr[l] > arr[h]:
				l = l + 1
			else:
				h = h - 1
		return arr[l]


from typing import List

class Solution:

	def chocolates(self, n: int, arr: List[int]) -> int:
		while len(arr) > 1:
			if arr[len(arr) - 1] > arr[0]:
				arr.pop()
			else:
				arr.pop(0)
		return arr[0]


from typing import List

class Solution:

	def chocolates(self, n: int, arr: List[int]) -> int:
		for i in range(len(arr)):
			a = min(arr)
			return a


from typing import List

class Solution:

	def chocolates(self, n: int, arr: List[int]) -> int:
		lo = 0
		hi = n - 1
		while lo < hi:
			if arr[lo] > arr[hi]:
				lo = lo + 1
			else:
				hi = hi - 1
		return arr[lo]