Problem: You are given an array A of length N. Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide A into?

Submission attempts (in order):
# _*_ coding:utf-8 _*_



def solveProblem(allNumber,aSequence):
	flag="Flat"
	count = 1
	for i in range(allNumber-1):
		diff = aSequence[i+1]-aSequence[i]
		if flag == "Plus":
			if diff < 0:
				flag=="Flat"
				count=count+1
		elif flag == "Minus":
			if diff > 0:
				flag="Flat"
				count = count+1
		else:
			if diff > 0 :
				flag="Plus"
			else:
				flag="Minus"

	answer = count
	return answer


if __name__ == '__main__':
	N = int(input().strip())
	As = list(map(int,input().strip().split(' ')))
	solution = solveProblem(N,As)
	print("{}".format(solution))


# _*_ coding:utf-8 _*_



def solveProblem(allNumber,aSequence):
	flag="Flat"
	count = 1
	for i in range(allNumber-1):
		if flag == "Plus":
			if aSequence[i+1] < aSequence[i]:
				flag=="Flat"
				count=count+1
		elif flag == "Minus":
			if aSequence[i] < aSequence[i+1]:
				flag="Flat"
				count = count+1
		else:
			if aSequence[i] <  aSequence[i+1]:
				flag="Plus"
			else:
				flag="Minus"

	answer = count
	return answer


if __name__ == '__main__':
	N = int(input().strip())
	As = list(map(int,input().strip().split(' ')))
	solution = solveProblem(N,As)
	print("{}".format(solution))


# _*_ coding:utf-8 _*_



def solveProblem(allNumber,aSequence):
	flag="Flat"
	count = 1
	for i in range(allNumber-1):
		diff = aSequence[i+1]-aSequence[i]
		if flag == "Plus":
			if diff < 0:
				flag=="Flat"
				count=count+1
		elif flag == "Minus":
			if diff > 0:
				flag="Flat"
				count = count+1
		else:
			if diff > 0 :
				flag="Plus"
			elif diff < 0:
				flag="Minus"

	answer = count
	return answer


if __name__ == '__main__':
	N = int(input().strip())
	As = list(map(int,input().strip().split(' ')))
	solution = solveProblem(N,As)
	print("{}".format(solution))


# _*_ coding:utf-8 _*_



def solveProblem(allNumber,aSequence):
	flag="Flat"
	count = 1
	for i in range(allNumber-1):
		diff = aSequence[i+1]-aSequence[i] 
		if flag == "Plus":
			if diff < 0:
				flag=="Flat"
				count=count+1
		elif flag == "Minus":
			if diff > 0:
				flag="Flat"
				count = count+1
		else:
			if diff > 0 :
				flag="Plus"
			else:
				flag="Minus"

	answer = count
	return answer


if __name__ == '__main__':
	N = int(input().strip())
	As = list(map(int,input().strip().split(' ')))
	solution = solveProblem(N,As)
	print("{}".format(solution))


# _*_ coding:utf-8 _*_



def solveProblem(allNumber,aSequence):
	flag="Flat"
	count = 1
	for i in range(allNumber-1):
		diff = aSequence[i+1]-aSequence[i] 
		if flag == "Plus":
			if diff < 0:
				flag=="Flat"
				count=count+1
		elif flag == "Minus":
			if diff > 0:
				flag="Flat"
				count = count+1
		else:
			if diff > 0 :
				flag="Plus"
			else:
				flag="Minus"

	answer = count
	return answer


if __name__ == '__main__':
	N = int(input().strip())
	As = list(map(int,input().strip().split(' ')))
	solution = solveProblem(N,As)
	print("{}".format(solution))


# _*_ coding:utf-8 _*_



def solveProblem(allNumber,aSequence):
	flag="Flat"
	count = 1
	for i in range(allNumber-1):
		diff = aSequence[i+1]-aSequence[i]
		if flag == "Plus":
			if diff < 0:
				flag="Flat"
				count=count+1
		elif flag == "Minus":
			if diff > 0:
				flag="Flat"
				count = count+1
		else:
			if diff > 0 :
				flag="Plus"
			elif diff < 0:
				flag="Minus"

	answer = count
	return answer


if __name__ == '__main__':
	N = int(input().strip())
	As = list(map(int,input().strip().split(' ')))
	solution = solveProblem(N,As)
	print("{}".format(solution))


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted