There is an array contains some non-negative integers. Check whether the array is perfect or not. An array is called perfect if it is first strictly increasing, then constant and finally strictly decreasing. Any of the three parts can be empty.
 
Example 1:
Input : Arr[] = {1, 8, 8, 8, 3, 2}
Output : Yes
Explanation:
We have an array [1, 8, 8, 8, 3, 2]. 
If we look in the range [0, 1] then 
we find that in this range the array is 
increasing, in the range [1, 3] the array 
is constant and in the range [3, 4] the 
array is decreasing.So, it satisfies the above 
condition then we return true.
Example 2:
Input : Arr[] = {1, 1, 2, 2, 1}
Output : No
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 checkUnimodal() that takes an array (arr), sizeOfArray (n), and return bool value that is true if condition satisfied else false. 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^{8}

Difficulty: EASY
Tags: Data structures
Skill types: Data structures
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).

Starter code:
#User function Template for python3

class Solution:
    def checkUnimodal(self,arr, n): 
          
        # Complete the function


Solutions:
class Solution:

	def checkUnimodal(self, arr, n):
		i = 1
		while i < n and arr[i] > arr[i - 1]:
			i += 1
		while i < n and arr[i] == arr[i - 1]:
			i += 1
		while i < n and arr[i] < arr[i - 1]:
			i += 1
		if i == n:
			return 1
		return 0


class Solution:

	def checkUnimodal(self, arr, n):
		if n == 1:
			return True
		if n == 2:
			if arr[0] < arr[-1]:
				return False
			else:
				return True
		if arr[0] > arr[1]:
			stage = 2
		elif arr[0] == arr[1]:
			stage = 1
		else:
			stage = 0
		for i in range(n - 1):
			if arr[i] < arr[i + 1]:
				if stage == 0:
					continue
				else:
					return False
			elif arr[i] == arr[i + 1]:
				if stage == 0 or stage == 1:
					stage = 1
				else:
					return False
			elif arr[i] > arr[i + 1]:
				if stage == 1 or stage == 2 or stage == 0:
					stage = 2
				else:
					return False
		return True


class Solution:

	def checkUnimodal(self, arr, n):
		(a, b, c, i) = ([], [], [], 0)
		while i < n - 1:
			if arr[i] - arr[i + 1] < 0:
				a.append(i)
			elif arr[i] - arr[i + 1] == 0:
				b.append(i)
			elif arr[i] - arr[i + 1] > 0:
				c.append(i)
			i += 1
		if a + b + c + [n - 1] == sorted(a + b + c + [n - 1]):
			return 1
		return 0


class Solution:

	def checkUnimodal(self, arr, n):
		condition = 1
		for index in range(n - 1):
			if arr[index] < arr[index + 1] and condition == 1:
				continue
			elif arr[index] == arr[index + 1] and condition == 1:
				condition = 2
			elif arr[index] == arr[index + 1] and condition == 2:
				continue
			elif arr[index] > arr[index + 1] and condition in [1, 2]:
				condition = 3
			elif arr[index] > arr[index + 1] and condition == 3:
				continue
			else:
				return False
		return True


class Solution:

	def checkUnimodal(self, arr, n):
		i = 0
		j = n - 1
		while i < n - 1:
			if arr[i] < arr[i + 1]:
				i += 1
			else:
				break
		while j > 0:
			if arr[j] < arr[j - 1]:
				j -= 1
			else:
				break
		for k in range(i, j, 1):
			if arr[k] != arr[k + 1]:
				return 0
				break
		return 1


class Solution:

	def checkUnimodal(self, arr, n):
		inc = True
		dec = False
		for i in range(1, n):
			if arr[i] >= arr[i - 1]:
				if dec:
					return False
				inc = True
			elif arr[i] < arr[i - 1]:
				if not inc:
					return False
				dec = True
		return True


class Solution:

	def checkUnimodal(self, arr, n):
		i = 1
		while i < n and arr[i] > arr[i - 1]:
			i += 1
		while i < n and arr[i] == arr[i - 1]:
			i += 1
		while i < n and arr[i] < arr[i - 1]:
			i += 1
		if i == n:
			return True
		else:
			return False


class Solution:

	def checkUnimodal(self, arr, n):
		if n == 1:
			return True
		state = -1
		if arr[1] > arr[0]:
			state = 0
		elif arr[1] == arr[0]:
			state = 1
		else:
			state = 2
		ans = True
		i = 0
		for i in range(2, n, 1):
			if state == 0:
				if arr[i] < arr[i - 1]:
					state = 2
				elif arr[i] == arr[i - 1]:
					state = 1
				else:
					continue
			if state == 1:
				if arr[i] == arr[i - 1]:
					continue
				elif arr[i] > arr[i - 1]:
					ans = False
					break
				else:
					state = 2
			if state == 2:
				if arr[i] >= arr[i - 1]:
					ans = False
					break
				else:
					continue
		return ans


class Solution:

	def checkUnimodal(self, arr, n):
		lim = 1
		while lim < n and arr[lim] > arr[lim - 1]:
			lim += 1
		while lim < n and arr[lim] == arr[lim - 1]:
			lim += 1
		while lim < n and arr[lim] < arr[lim - 1]:
			lim += 1
		return lim == n


class Solution:

	def checkUnimodal(self, arr, n):
		ma = max(arr)
		mi = min(arr)
		(i, so) = (0, 4)
		l = []
		while i != n - 1:
			if arr[i] < arr[i + 1]:
				if so == 4 or so == 1:
					so = 1
				else:
					return False
			elif arr[i] == arr[i + 1]:
				if so == 1 or so == 4 or so == 2:
					so = 2
				else:
					return False
			elif arr[i] > arr[i + 1]:
				if so == 1 or so == 2 or so == 4 or (so == 3):
					so = 3
				else:
					return False
			i += 1
		return True


class Solution:

	def checkUnimodal(self, arr, n):
		inc = True
		const = False
		dec = False
		base = arr[0]
		for i in range(1, n):
			if arr[i] > base:
				if const or dec:
					return False
			elif arr[i] == base:
				const = True
				if dec:
					return False
			else:
				dec = True
			base = arr[i]
		return True


class Solution:

	def checkUnimodal(self, arr, n):
		m = max(arr)
		f = arr.index(m)
		l = 0
		for i in range(n - 1, 0, -1):
			if arr[i] == m:
				l = i
				break
		for i in range(n):
			if i < f:
				if arr[i] < arr[i + 1]:
					pass
				else:
					return False
			elif i <= l and i >= f:
				if arr[i] == m:
					pass
				else:
					return False
			elif i > l:
				if arr[i] < arr[i - 1]:
					pass
				else:
					return False
		return True


class Solution:

	def checkUnimodal(self, arr, n):
		inc = 0
		cons = 0
		dec = 0
		for i in range(n - 1):
			if arr[i] < arr[i + 1]:
				inc = 1
				if cons == 1 or dec == 1:
					return False
			elif arr[i] == arr[i + 1]:
				cons = 1
				if dec == 1:
					return False
			elif arr[i] > arr[i + 1]:
				dec = 1
		return True


class Solution:

	def checkUnimodal(self, arr, n):
		inc = 0
		cons = 0
		dec = 0
		i = 1
		while i < n and arr[i - 1] < arr[i]:
			i += 1
			continue
		while i < n and arr[i - 1] == arr[i]:
			i += 1
			continue
		while i < n and arr[i - 1] > arr[i]:
			i += 1
			continue
		return i == n


class Solution:

	def checkUnimodal(self, a, n):
		i = 0
		while i < n - 1:
			if a[i] <= a[i + 1]:
				i += 1
			else:
				break
		j = n - 1
		while j > 0:
			if a[j] < a[j - 1]:
				j -= 1
			else:
				break
		for m in range(i, j):
			if a[m] != a[m + 1]:
				return False
		return True


class Solution:

	def checkUnimodal(self, arr, n):
		second = False
		for i in range(n - 1):
			if second == False and arr[i] <= arr[i + 1]:
				continue
			if arr[i] > arr[i + 1]:
				second = True
				continue
			return False
		return True


class Solution:

	def checkUnimodal(self, arr, n):
		i = 1
		while i < n and arr[i] > arr[i - 1]:
			i += 1
		while i < n and arr[i] == arr[i - 1]:
			i += 1
		while i < n and arr[i] < arr[i - 1]:
			i += 1
		return i == n
for _ in range(0, int(input())):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	ob = Solution()
	if ob.checkUnimodal(arr, n):
		print('Yes')
	else:
		print('No')


class Solution:

	def checkUnimodal(self, arr, n):
		i = 0
		while i < n - 1:
			if arr[i] < arr[i + 1]:
				i += 1
			else:
				break
		while i < n - 1:
			if arr[i] == arr[i + 1]:
				i += 1
			else:
				break
		while i < n - 1:
			if arr[i] > arr[i + 1]:
				i += 1
			else:
				break
		if i != n - 1:
			return False
		else:
			return True


class Solution:

	def checkUnimodal(self, arr, n):
		inc = False
		eq = False
		dce = False
		for i in range(n - 1):
			if arr[i] > arr[i + 1]:
				dce = True
				inc = False
				eq = False
			elif arr[i] == arr[i + 1]:
				eq = True
				inc = False
			elif arr[i] < arr[i + 1]:
				inc = True
			if dce and eq or (dce and inc):
				break
			if eq and inc:
				break
		else:
			return True
		return False


class Solution:

	def checkUnimodal(self, a, n):
		prev = a[0]
		incr = True
		con = True
		dec = True
		for i in range(1, n):
			if a[i] > prev and incr == True:
				prev = a[i]
			elif a[i] == prev and con == True:
				prev = a[i]
				inc = False
			elif a[i] < prev:
				prev = a[i]
				incr = False
				con = False
			else:
				return False
		return True