def schedule(graph):
	"""
	Method to perform topological sorting of the input graph (in adjacency list format) to find a valid schedule
	Complexity: O(V+E) time and O(V+E) space
	
	:return: The correct order of courses to be taken or null list if no valid order found
	:rtype: List[int]
	"""
	numCourses = len(graph) # number of courses
	indegree = [[] for _ in range(numCourses)]  # indegree
	outdegree = [0] * numCourses  # outdegree

	# Calculate the indegree and outdegree of each vertex
	for i in range(numCourses):
		outdegree[i] = len(graph[i])
		if len(graph[i])>0:
			for prereq in graph[i]:
				indegree[prereq].append(i)
	
	order = []
	# First we can take the courses with no prerequisites
	for i in range(numCourses):
		if outdegree[i]==0:
			order.append(i)
	
	ctr = 0
	# Perform Topo Sort to get the order of the rest of the courses
	while ctr!=len(order):
		v = order[ctr]
		ctr += 1
		for u in indegree[v]:
			outdegree[u] -= 1
			if outdegree[u] == 0:
				order.append(u)
	
	return order if ctr == numCourses else []