Given a Binary Search Tree. The task is to find the minimum valued element in this given BST. 
Example 1:
Input:
           5
         /    \
        4      6
       /        \
      3          7
     /
    1
Output: 1
Example 2:
Input:
             9
              \
               10
                \
                 11
Output: 9
Your Task:
The task is to complete the function minValue() which takes root as the argument and returns the minimum element of BST. If the tree is empty, there is no minimum element, so return -1 in that case.
Expected Time Complexity: O(Height of the BST)
Expected Auxiliary Space: O(1).
Constraints:
0 <= N <= 10^{4}

Source: geeksforgeeks | Difficulty: EASY
Tags: Tree algorithms

Data structures

Range queries

Starter code: #User function Template for python3



"""

class Node:

    def __init__(self, val):

        self.right = None

        self.data = val

        self.left = None

"""



#Function to find the minimum element in the given BST.

def minValue(root):

    ##Your code here

Solutions:
def minValue(root):
	li = []
	q = [root]
	while q:
		obg = q.pop()
		if obg:
			li.append(obg.data)
			q.append(obg.left)
			q.append(obg.right)
	if li:
		return min(li)
	return -1


def minValue(root):
	if not root:
		return -1
	if root.left is None:
		return root.data
	return minValue(root.left)


class Node:

	def __init__(self, val):
		self.right = None
		self.data = val
		self.left = None

def minValue(root):
	if root == None:
		return -1
	while root.left is not None:
		root = root.left
	return root.data


def minValue(root):
	if root == None:
		return -1
	if root.left == None:
		return root.data
	return minValue(root.left)


def minValue(root):
	if root == None:
		return -1
	while root:
		val = root.data
		root = root.left
	return val


def minValue(root):
	if root is None:
		return -1
	if root.left is None:
		return root.data
	else:
		return minValue(root.left)


def minValue(root):
	if root == None:
		return -1
	elif root.left == None:
		return root.data
	else:
		return minValue(root.left)


def minValue(root):
	if root is None:
		return -1
	currentNode = root
	while currentNode.left is not None:
		currentNode = currentNode.left
	return currentNode.data


import sys

def minu(root, mini):
	if not root:
		return
	minu(root.left, mini)
	mini[0] = min(mini[0], root.data)
	minu(root.right, mini)

def minValue(root):
	mini = [sys.maxsize]
	minu(root, mini)
	if mini[0] == sys.maxsize:
		return -1
	return mini[0]


def minValue(root):
	if root is None:
		return -1
	current = root
	while current.left is not None:
		current = current.left
	if current:
		return current.data
	else:
		return -1


def minValue(root):
	mini = -1
	while root != None:
		mini = root.data
		root = root.left
	return mini


def minValue(root):
	if root is None:
		return -1
	elif root.left is None:
		return root.data
	while root.left:
		root = root.left
	return root.data


def minValue(root):
	if not root:
		return -1
	minVal = [root.data]

	def findMin(node):
		if not node:
			return
		minVal[0] = min(minVal[0], node.data)
		findMin(node.left)
	findMin(root)
	return minVal[0]


def minValue(root):
	if not root:
		return -1
	while root.left:
		root = root.left
	return root.data


import math

def minValue(root):
	if not root:
		return -1
	minValue = [root.data]

	def findMin(node):
		if not node:
			return
		minValue[0] = min(minValue[0], node.data)
		findMin(node.left)
	findMin(root)
	return minValue[0]


def minValue(root):
	if not root:
		return -1
	s = [root]
	res = [root.data]
	while s:
		node = s.pop(0)
		if node.left:
			s.append(node.left)
			res.append(node.left.data)
		if node.right:
			s.append(node.right)
			res.append(node.right.data)
	return min(res)


def minValue(root):
	ls = []

	def tree(root):
		if root != None:
			tree(root.left)
			ls.append(root.data)
			tree(root.right)
	if root == None:
		return -1
	else:
		tree(root)
	ls.sort()
	return ls[0]


def minValue(root):
	Null = None
	if root == None:
		return -1
	min = root.data
	while root != Null:
		if min > root.data:
			min = root.data
		root = root.left
	return min


def minValue(root):
	a = []

	def rec(root):
		if root:
			rec(root.left)
			rec(root.right)
			a.append(root.data)
	rec(root)
	if root:
		return min(a)
	else:
		return -1


def minValue(root):
	stack = [(root, False)]
	while stack:
		(node, visited) = stack.pop()
		if visited:
			return node.data
		elif node:
			stack.append((node.right, False))
			stack.append((node, True))
			stack.append((node.left, False))
	return -1


def minValue(root):
	if root == None:
		return -1
	ans = root
	while ans.left:
		ans = ans.left
	return ans.data


def minValue(root):
	if root is None:
		return -1
	while True:
		if root:
			l = root.data
			root = root.left
		else:
			break
	return l


def minValue(root):
	parent = -1
	while root:
		parent = root.data
		root = root.left
	return parent


def minValue(root):
	res = None
	while root:
		res = root.data
		root = root.left
	return res if res else -1


def minValue(root):
	if root is None:
		return -1
	return minValueHelper(root)

def minValueHelper(root):
	if root is None:
		return 100000
	left_tree = minValueHelper(root.left)
	return min(root.data, left_tree)


import math

def minValue(root):
	if not root:
		return -1
	minVal = [math.inf]

	def dfs(node):
		if not node:
			return
		minVal[0] = min(minVal[0], node.data)
		dfs(node.left)
	dfs(root)
	return minVal[0]


def minValue(root):
	if root is None:
		return -1
	stack = []
	current = root
	result = []
	while current or stack:
		while current:
			stack.append(current)
			current = current.left
		current = stack.pop()
		result.append(current.data)
		current = current.right
	return result[0]


def minValue(root):
	if not root:
		return -1
	stack = [root]
	min = 1000000
	while stack:
		node = stack.pop()
		if node.data < min:
			min = node.data
		if node.right:
			stack.append(node.right)
		if node.left:
			stack.append(node.left)
	return min


def findmin(root):
	if root is None:
		return -1
	while root.left != None:
		root = root.left
	return root.data

def minValue(root):
	return findmin(root)


def minValue(root):
	ptr = root
	if root is None:
		return -1
	while ptr.left:
		ptr = ptr.left
	return ptr.data


def minValue(root):
	if not root:
		return -1
	z = []

	def pre(root, z):
		if root:
			z.append(root.data)
			pre(root.left, z)
			pre(root.right, z)
	pre(root, z)
	return min(z)


def minValue(root):
	if root == None:
		return -1
	min1 = root.data
	while root:
		if min1 > root.data:
			min1 = root.data
		root = root.left
	return min1


def minValue(root):
	if root is None:
		return -1
	if root.left is None and root.right is None:
		return root.data
	if root.left:
		return minValue(root.left)
	return root.data


def minValue(root):
	a = []
	while root != None:
		a.append(root.data)
		root = root.left
	if len(a) > 0:
		return min(a)
	else:
		return -1


def minValue(root):
	if root == None:
		return -1
	while root.left != None:
		if root.left.data < root.data:
			root = root.left
		else:
			root = root.right
	return root.data


def order(node, a):
	if node is None:
		return
	order(node.left, a)
	a.append(node.data)
	order(node.right, a)
	return a

def minValue(root):
	if root is None:
		return -1
	x = order(root, [])
	return min(x)


def minValue(root):
	if root is None:
		return -1
	cur = root
	while root.left != None:
		root = root.left
	mi = root.data
	return mi


def slove(root):
	if root is None:
		return -1
	while root.left != None:
		root = root.left
	return root.data

def minValue(root):
	return slove(root)


def minValue(root):
	return _minValue(root)

def _minValue(node):
	if node is None:
		return -1
	elif node.left is None:
		return node.data
	else:
		return _minValue(node.left)


import math

def minValue(root):
	if root is None:
		return -1
	m = math.inf
	if root.data < m:
		m = root.data
	if root.left is not None:
		m = minValue(root.left)
	return m


def minValue(root):
	ans = -1
	while root:
		ans = root.data
		root = root.left
	return ans


def minValue(root):
	if root is None:
		return -1
	node = root
	node2 = None
	while node:
		node2 = node
		node = node.left
	return node2.data


def minValue(root):
	if not root:
		return -1
	flag = 1
	if not root.left:
		flag = 0
	node = root
	while flag:
		if not node.left:
			flag = 0
		else:
			node = node.left
	return node.data


def minValue(root):
	ans = float('inf')
	stack = []
	if root is not None:
		stack.append(root)
	while len(stack) > 0:
		curr = stack.pop()
		if curr.data < ans:
			ans = curr.data
		if curr.left is not None:
			stack.append(curr.left)
		if curr.right is not None:
			stack.append(curr.right)
	if ans == float('inf'):
		return -1
	else:
		return ans


def minValue(root):
	ans = float('inf')

	def h(root):
		if not root:
			return float('inf')
		a = h(root.left)
		return min(a, root.data)
	ans = h(root)
	return ans if ans != float('inf') else -1


def minValue(root):
	if root == None:
		return -1
	temp = root
	while temp.left != None:
		temp = temp.left
	return temp.data


import math

def minimum_element(root):
	if not root:
		return math.inf
	return min(root.data, minimum_element(root.left), minimum_element(root.right))

def minValue(root):
	result = minimum_element(root)
	if result == math.inf:
		return -1
	return result


def minValue(root):
	if not root:
		return -1
	if not root.left:
		return root.data
	else:
		return minValue(root.left)


def minValue(root):
	minimum = float('inf')
	if root is None:
		return -1
	if root.left is None:
		return root.data
	while root is not None:
		minimum = min(root.data, minimum)
		root = root.left
	return minimum


def solve(root, ans):
	if root == None:
		return
	solve(root.left, ans)
	ans.append(root.data)
	solve(root.right, ans)

def minValue(root):
	ans = []
	solve(root, ans)
	if len(ans) == 0:
		return -1
	mi = ans[0]
	return mi


def minValue(root):
	if not root:
		return -1

	def minel(root):
		if not root.left:
			return root.data
		return minel(root.left)
	return minel(root)


def le(root, m):
	if root:
		m.append(root.data)
		le(root.left, m)

def minValue(root):
	m = []
	if root == None:
		return -1
	elif root.left != None:
		le(root, m)
		res = m.pop()
		return res
	else:
		return root.data


def fun(root, m):
	if root:
		m.append(root.data)
		fun(root.left, m)
		fun(root.right, m)

def minValue(root):
	m = []
	res = fun(root, m)
	if len(m) == 0:
		return -1
	else:
		return min(m)


def minValue(root):
	if root == None:
		return -1
	while True:
		if root.left == None:
			return root.data
		else:
			root = root.left


def minValue(root):
	if root == None:
		return -1
	x = root.data
	while root != None:
		if x > root.data:
			x = root.data
		root = root.left
	return x


def minValue(root):
	if not root:
		return -1
	else:
		minimum = root.data
		if root.left != None:
			minimum = min(minimum, minValue(root.left))
		if root.right != None:
			minimum = min(minimum, minValue(root.right))
	return minimum