Given a date, the task is to check if it is valid or not. It may be assumed that the given date is in range from 01/01/1800 to 31/12/9999 and any date not within this range will also be considered invalid.
 
Example 1:
Input:
d = 10, m = 12, y = 2000
Output:
1
Explanation:
The given date 10/12/2000 is valid.
Example 2:
Input:
d = 30, m = 2, y = 1700
Output:
0
Explanation:
The given date 30/2/1700 is invalid.
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function isValidDate() which takes 3 Integers d,m and y as input and returns the answer.
 
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= d, m, y <= 10000

Difficulty: EASY
Tags: Mathematics
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3



class Solution:

    def isValidDate(self, d, m, y):

        # code here 

Solutions:
class Solution:

	def isValidDate(self, d, m, y):
		mon = [1, 3, 5, 7, 8, 10, 12]
		if m in mon and (y <= 9999 and y >= 1800):
			if d < 32:
				return 1
			else:
				return 0
		elif (m not in mon and m <= 12) and m != 2:
			if d <= 30 and (y <= 9999 and y >= 1800):
				return 1
			else:
				return 0
		elif m == 2 and (y <= 9999 and y >= 1800):
			if y % 4 == 0 and y % 400 == 0:
				if d <= 29:
					return 1
				else:
					return 0
			elif y % 100 == 0 and y % 400 != 0:
				if d <= 28:
					return 1
				else:
					return 0
			elif y % 4 == 0 and y % 100 != 0:
				if d <= 29:
					return 1
				else:
					return 0
			elif y % 4 != 0:
				if d <= 28:
					return 1
				else:
					return 0
		else:
			return 0


class Solution:

	def isValidDate(self, d, m, y):
		if y < 1800 or y > 9999:
			return 0

		def leap(n):
			if n % 400 == 0 or (n % 4 == 0 and n % 100 != 0):
				return True
			return False
		if m < 0 or m > 12:
			return 0
		if d < 0 or d > 31:
			return 0
		if m == 2:
			if leap(y):
				if d > 29:
					return 0
				return 1
			else:
				if d > 28:
					return 0
				return 1
		if m == 4 or m == 6 or m == 9 or (m == 11):
			if d <= 30:
				return 1
			return 0
		return 1


from datetime import date

class Solution:

	def isValidDate(self, d, m, y):
		if y < 1800:
			return 0
		try:
			t = date(y, m, d)
			return 1
		except:
			return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(d, m, y) = map(int, input().split())
		ob = Solution()
		print(ob.isValidDate(d, m, y))


class Solution:

	def isLeap(self, year):
		return year % 4 == 0 and year % 100 != 0 or year % 400 == 0

	def isValidDate(self, d, m, y):
		if y > 9999 or y < 1800:
			return 0
		if m < 1 or m > 12:
			return 0
		if d < 1 or d > 31:
			return 0
		if m == 2:
			if self.isLeap(y):
				if d <= 29:
					return 1
				else:
					return 0
			elif d <= 28:
				return 1
			else:
				return 0
		if m == 4 or m == 6 or m == 9 or (m == 11):
			if d <= 30:
				return 1
			else:
				return 0
		return 1
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(d, m, y) = map(int, input().split())
		ob = Solution()
		print(ob.isValidDate(d, m, y))


import calendar

class Solution:

	def isValidDate(self, d, m, y):
		if d > 0 and d < 32 and (m > 0) and (m < 13) and (y > 1799) and (y < 10000):
			mo = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
			if d <= mo[m]:
				return 1
			if calendar.isleap(y):
				if d == 29:
					return 1
		return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(d, m, y) = map(int, input().split())
		ob = Solution()
		print(ob.isValidDate(d, m, y))


class Solution:

	def isValidDate(self, d, m, y):
		z = 0
		if y % 400 == 0 or (y % 4 == 0 and y % 100 != 0):
			if m == 2 and d <= 29 and (1800 <= y <= 9999):
				z = 1
			if d <= 31 and m in (1, 3, 5, 7, 8, 10, 12) and (1800 <= y <= 9999):
				z = 1
			if d <= 30 and m in (4, 6, 9, 11) and (1800 <= y <= 9999):
				z = 1
		else:
			if m == 2 and d <= 28 and (1800 <= y <= 9999):
				z = 1
			if d <= 31 and m in (1, 3, 5, 7, 8, 10, 12) and (1800 <= y <= 9999):
				z = 1
			if d <= 30 and m in (4, 6, 9, 11) and (1800 <= y <= 9999):
				z = 1
		if z == 1:
			return 1
		else:
			return 0