Given an array of integers in[] representing inorder traversal of elements of a binary tree. Return true if the given inorder traversal can be of a valid Binary Search Tree.
Note - All the keys in BST must be unique
 
Example 1:
Input: in = [8, 14, 45, 64, 100]
Output: True
Example 2:
Input: in[] = [5, 6, 1, 8, 7]
Output: False
 
Your Task:
Complete the function isBSTTraversal() which takes an integer array in[] as input and return true if the traversal represents a BST.
 
Expected Time Complexity: O(n)
Expected Space Complexity: O(1)
 
Constraints:
1<=n<=10^{5}
1<=in[i]<=10^{9}

Source: geeksforgeeks | Difficulty: EASY

Starter code: #User function Template for python3



class Solution:

    def isBSTTraversal(self, nums):

        # Code here

Solutions:
class Solution:

	def isBSTTraversal(self, nums):
		for idx in range(1, len(nums)):
			if nums[idx - 1] >= nums[idx]:
				return False
		return True


class Solution:

	def isBSTTraversal(self, nums):
		for i in range(len(nums) - 1):
			if nums[i] >= nums[i + 1]:
				return False
		else:
			return True


class Solution:

	def isBSTTraversal(self, nums):
		return len(set(nums)) == len(nums) and sorted(nums) == nums


class Solution:

	def isBSTTraversal(self, nums):
		i = 1
		while i < len(nums):
			if nums[i - 1] >= nums[i]:
				return False
			i += 1
		return True


class Solution:

	def isBSTTraversal(self, nums):
		if len(nums) == 0:
			return True
		prev = nums[0]
		for i in range(1, len(nums)):
			if nums[i] <= prev:
				return False
			prev = nums[i]
		return True


class Solution:

	def isBSTTraversal(self, nums):
		n = len(nums)
		i = 0
		j = 1
		while i <= n - 2:
			if nums[i] >= nums[j]:
				return False
			j += 1
			i += 1
		return True


class Solution:

	def isBSTTraversal(self, n):
		max = n[0]
		for i in range(1, len(n)):
			if max >= n[i]:
				return False
			max = n[i]
		return True


class Solution:

	def isBSTTraversal(self, nums):
		return nums == sorted(set(nums))


from collections import Counter

class Solution:

	def isBSTTraversal(self, nums):
		n = len(nums)
		c = Counter(nums)
		for key in c:
			if c[key] > 1:
				return False
		res = True
		for i in range(n - 1):
			if nums[i] > nums[i + 1]:
				res = False
		return res


class Solution:

	def isBSTTraversal(self, nums):
		if nums == sorted(list(set(nums))):
			return 'True'
		return 'False'


class Solution:

	def isBSTTraversal(self, nums):
		if nums == sorted(nums) and len(set(nums)) == len(nums):
			return True
		return False


class Solution:

	def isBSTTraversal(self, nums):
		n = len(nums)
		if n < 3:
			return False
		for i in range(1, n - 1):
			if (nums[i - 1] < nums[i] and nums[i] < nums[i + 1]) is False:
				return False
		return True


class Solution:

	def isBSTTraversal(self, nums):
		for i in range(1, n):
			if nums[i] <= nums[i - 1]:
				return False
		return True


class Solution:

	def isBSTTraversal(self, arr):
		n = len(arr)
		for i in range(n - 1):
			if arr[i] >= arr[i + 1]:
				return False
		return True


class Solution:

	def isBSTTraversal(self, nums):
		ma = -1
		for i in nums:
			if i > ma:
				ma = i
			else:
				return False
		return True