Akku have solved many problems, she is genius. One day her friend gave her an Array of size n and asked her to perform
some queries of following type:
Each query consists of three integers
1 A B : Update the Array at index A by value B
2 A B : if the subarray from index A to B (both inclusive) is
        1. Both increasing(Non-decreasing) and decreasing(Non-increasing) print -1
        2. Only increasing(Non-decreasing) print 0
        3. Only decreasing(Non-increasing) print 1
        4. Neither increasing nor decreasing print -1
Akku needs your help, can you help her.
 
Example 1:
Input: nums = {1,5,7,4,3,5,9},
Queries = {{2,1,3},{1,7,4},{2,6,7}}
Output: {0,1}
Explanation: For the 1st query given :
A = 1, B = 3. From 1 to 3(1,5,7) elements 
are in increasing order. So answer is 0.
For the 2nd query we have to update the 7th
element of the array by 4. So new updated array
will be {1,5,7,4,3,5,4}
For the 3rd query A = 6, B = 7. From 6 to 7
(5, 4) elements are in descending order. So 
answer is 1.
 
Your Task:
You don't need to read or print anything. Your task is to complete the function solveQueries() which takes nums and Queries as input parameter and returns a list containing the answer for the 2nd type of query.
 
Expected Time Comeplxity: O(n*log(n))
Expected Space Comeplxity: O(n)
 
Constraints:
1 <= n <= 10^{4}
1 <= nums[i] <= 10^{4}
1 <= No. of queries <= 10^{4}

Source: geeksforgeeks | Difficulty: MEDIUM_HARD
Tags: Data structures

Range queries

Segment trees revisited

Starter code: #User function Template for python3

class Solution:
	def solveQueries(self, nums, Queries):
		#Code here

Solutions:
class Solution:

	def algo(self, a):
		l = list(a)
		l.sort()
		l1 = l[::-1]
		if len(a) == 1:
			return -1
		if a == l:
			return 0
		if a == l1:
			return 1
		return -1

	def solveQueries(self, nums, q):
		ans = []
		for i in range(len(q)):
			l = q[i]
			if l[0] == 1:
				nums[l[1] - 1] = l[2]
			elif l[0] == 2:
				a = nums[l[1] - 1:l[2]]
				ans.append(self.algo(a))
		return ans


class Solution:

	def solveQueries(self, nums, Queries):
		ans = []
		for (q, A, B) in Queries:
			if q == 1:
				nums[A - 1] = B
			if q == 2:
				s = set()
				for (x0, x1) in zip(nums[A - 1:B - 1], nums[A:B]):
					r = '<' if x0 < x1 else '>' if x0 > x1 else '='
					s.add(r)
				r = -1 if not s else 0 if '>' not in s else 1 if '<' not in s else -1
				ans.append(r)
		return ans