Given a Number N in String form, Print 1 If the digits of the number are in non-decreasing or non-increasing order, else print 0.
 
Example 1:
Input:
N = "1233"
Output:
1
Explanation:
The digits of the number are in non-
decreasing order. So, the Output is 1.
Example 2:
Input:
N = "1263"
Output:
0
Explanation:
The digits of the number are neither in
non-decreasing nor in non-increasing order.
So, the Output is 0.
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function difProblem() which takes a String N as input and returns 0 or 1.
 
Expected Time Complexity: O(|N|)
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= |N| <= 10^{5}

Difficulty: EASY
Expected Time Complexity: O(|N|)
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3



class Solution:

    def difProblem(self, N):

        # code here 

Solutions:
class Solution:

	def difProblem(self, N):
		a = sorted(N)
		s = ''
		for i in a:
			s += i
		s1 = s[::-1]
		if s == N or s1 == N:
			return 1
		return 0


class Solution:

	def difProblem(self, N):
		n = len(N)
		increasing = True
		decreasing = True
		for i in range(1, n):
			if N[i] < N[i - 1]:
				increasing = False
			if N[i] > N[i - 1]:
				decreasing = False
		if increasing or decreasing:
			return 1
		else:
			return 0


class Solution:

	def difProblem(self, N):
		l = []
		for i in N:
			l.append(int(i))
		x = sorted(l)
		y = x[::-1]
		if x == l or y == l:
			return 1
		return 0


class Solution:

	def difProblem(self, N):
		p = len(N)
		if p == 1:
			return 1
		if int(N[0]) < int(N[p - 1]):
			for i in range(p - 1):
				if int(N[i]) <= int(N[i + 1]):
					pass
				else:
					return 0
		else:
			for i in range(p - 1):
				if int(N[i]) >= int(N[i + 1]):
					pass
				else:
					return 0
		return 1


class Solution:

	def difProblem(self, n):
		k = list(map(int, n))
		x = sorted(k)
		y = x[::-1]
		if k == x or k == y:
			return 1
		return 0


class Solution:

	def difProblem(self, N):
		A = list(N)
		A.sort()
		A = ''.join(A)
		B = A[::-1]
		if N == A:
			return 1
		elif N == B:
			return 1
		else:
			return 0


class Solution:

	def difProblem(self, N):
		non_decreasing = True
		for i in range(1, len(N)):
			if N[i] < N[i - 1]:
				non_decreasing = False
				break
		if non_decreasing:
			return 1
		non_increasing = True
		for i in range(1, len(N)):
			if N[i] > N[i - 1]:
				non_increasing = False
				break
		if non_increasing:
			return 1
		return 0


def increase(N):
	for i in range(len(N) - 1):
		if N[i] > N[i + 1]:
			return 0
	else:
		return 1

def decrease(N):
	for i in range(len(N) - 1):
		if N[i] < N[i + 1]:
			return 0
	else:
		return 1

class Solution:

	def difProblem(self, N):
		if increase(N) or decrease(N):
			return 1
		else:
			return 0


class Solution:

	def difProblem(self, N):
		x = [i for i in str(N)]
		if x == sorted(x):
			return 1
		if x == sorted(x)[::-1]:
			return 1
		return 0


class Solution:

	def difProblem(self, N):
		if len(N) <= 2:
			return 1
		if len(N) > 2:
			if N[0] > N[1]:
				for i in range(len(N) - 1):
					if N[i] < N[i + 1]:
						return 0
				return 1
			elif N[0] < N[1]:
				for i in range(len(N) - 1):
					if N[i] > N[i + 1]:
						return 0
				return 1
			return 0


class Solution:

	def difProblem(self, N):
		n = len(N)
		f = 0
		for i in range(n - 1):
			if N[i] > N[i + 1]:
				f = 1
				break
		if f == 0:
			return 1
		for i in range(n - 1):
			if N[i] < N[i + 1]:
				return 0
		return 1


class Solution:

	def difProblem(self, N):
		s = str(N)
		n = len(s)
		if n == 1 or n == 2:
			return 1
		for i in range(n - 1):
			if s[0] > s[1]:
				if s[i] < s[i + 1]:
					return 0
			elif s[i] > s[i + 1]:
				return 0
		if s[0] > s[1]:
			if s[n - 2] < s[n - 1]:
				return 0
		elif s[n - 2] > s[n - 1]:
			return 0
		return 1
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = input()
		ob = Solution()
		print(ob.difProblem(N))


class Solution:

	def increase(self, N):
		for i in range(0, len(N) - 1):
			if int(N[i]) > int(N[i + 1]):
				return 0
		return 1

	def decrease(self, N):
		for i in range(0, len(N) - 1):
			if int(N[i]) < int(N[i + 1]):
				return 0
		return 1

	def difProblem(self, N):
		if self.increase(N) or self.decrease(N):
			return 1
		return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = input()
		ob = Solution()
		print(ob.difProblem(N))


class Solution:

	def difProblem(self, N):
		temp = list(str(N))
		if temp == sorted(temp) or temp == sorted(temp, reverse=True):
			return 1
		else:
			return 0


class Solution:

	def difProblem(self, N):
		if len(N) == 0:
			return 0
		if len(N) == 1:
			return 1
		order = 'None'
		for i in range(1, len(N)):
			if N[i].isdigit() == False:
				return 0
			diff = int(N[i]) - int(N[i - 1])
			if diff > 0 and order == 'Non Increasing':
				return 0
			elif diff < 0 and order == 'Non Decreasing':
				return 0
			elif diff > 0 and order == 'None':
				order = 'Non Decreasing'
			elif diff < 0 and order == 'None':
				order = 'Non Increasing'
		return 1


class Solution:

	def difProblem(self, N):
		n = list(N)
		n = list(map(int, n))
		p = list(n[:])
		p.sort()
		if p == n:
			return 1
		p.sort(reverse=True)
		if p == n:
			return 1
		return 0


class Solution:

	def difProblem(self, N):
		n = len(N)
		forward = True
		reverse = True
		for i in range(1, n):
			if N[i] < N[i - 1]:
				forward = False
		for i in range(1, n):
			if N[i] > N[i - 1]:
				reverse = False
		if forward == True or reverse == True:
			return 1
		return 0


class Solution:

	def difProblem(self, N):
		a = []
		b = []
		c = []
		a.extend(str(N))
		b = a.copy()
		c = a.copy()
		b.sort()
		c.sort(reverse=True)
		if a == b or a == c:
			return 1
		else:
			return 0


class Solution:

	def difProblem(self, N):
		inc = 0
		dec = 0
		if len(N) in [1, 2]:
			return 1
		else:
			for i in range(len(N) - 1):
				if int(N[i]) >= int(N[i + 1]):
					inc += 1
				if int(N[i]) <= int(N[i + 1]):
					dec += 1
		if inc == len(N) - 1 or dec == len(N) - 1:
			return 1
		else:
			return 0


class Solution:

	def difProblem(self, N):
		a = []
		for i in N:
			a.append(int(i))
		if len(a) <= 1:
			return 1
		if a[0] > a[1]:
			for i in range(len(a) - 1):
				if a[i] < a[i + 1]:
					return 0
			return 1
		else:
			for i in range(len(a) - 1):
				if a[i] > a[i + 1]:
					return 0
			return 1


class Solution:

	def difProblem(self, N):
		f = 0
		k = list(N)
		k.sort()
		k = ''.join(k)
		if str(N) == k or str(N) == k[::-1]:
			f = 1
		return f


class Solution:

	def difProblem(self, N):
		l = list(N)
		for i in range(len(l)):
			l[i] = int(l[i])
		gg = sorted(l)
		gg1 = gg[::-1]
		if gg == l or gg1 == l:
			return 1
		else:
			return 0


class Solution:

	def difProblem(self, N):
		flag = 0
		if len(N) == 1:
			return 1
		if N[1] > N[0]:
			for i in range(1, len(N)):
				if N[i] < N[i - 1]:
					flag = 1
					break
			if flag == 0:
				return 1
		if N[1] < N[0]:
			for i in range(1, len(N)):
				if N[i] > N[i - 1]:
					flag = 1
					break
			if flag == 0:
				return 1
		return 0