Write a program that calculates the day of the week for any particular date in the past or future.
Example 1:
Input:
d = 28, m = 12, y = 1995
Output:
Thursday
Explanation:
28 December 1995 was a Thursday.
Example 2:
Input:
d = 30, m = 8, y = 2010
Output:
Monday
Explanation:
30 August 2010 was a Monday.
Your Task:
You don't need to read input or print anything. Your task is to complete the function getDayOfWeek() which takes 3 Integers d, m and y denoting day, month and year as input and return a String denoting the answer.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
Constraints:
1 <= d <= 31
1 <= m <= 12
1990 <= y <= 2100

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

Starter code:
#User function Template for python3

class Solution:
    def getDayOfWeek(self, d, m, y):
        # code here 

Solutions:
class Solution:

	def getDayOfWeek(self, d, m, y):
		ans = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
		t = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]
		if m < 3:
			y = y - 1
		x = (y + y // 4 + y // 400 - y // 100 + t[m - 1] + d) % 7
		return ans[x]


import calendar

class Solution:

	def getDayOfWeek(self, d, m, y):
		weekday = calendar.weekday(y, m, d)
		dict = {'Monday': 0, 'Tuesday': 1, 'Wednesday': 2, 'Thursday': 3, 'Friday': 4, 'Saturday': 5, 'Sunday': 6}
		key_list = list(dict.keys())
		val_list = list(dict.values())
		return key_list[val_list.index(weekday)]


import datetime

class Solution:

	def getDayOfWeek(self, d, m, y):
		res = datetime.datetime(y, m, d)
		return res.strftime('%A')


class Solution:

	def getDayOfWeek(self, d, m, y):
		day = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
		t = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]
		y -= m < 3
		res = (y + int(y / 4) - int(y / 100) + int(y / 400) + t[m - 1] + d) % 7
		return day[res]


class Solution:

	def getDayOfWeek(self, d, m, y):
		if m == 1 or m == 2:
			y = y - 1
			if m == 1:
				m = 11
			else:
				m = 12
		else:
			m = m - 2
		C = int(y / 100)
		Y = int(y % 100)
		weeks = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
		w = int((d + (2.6 * m - 0.2) - 2 * C + Y + int(Y / 4) + int(C / 4)) % 7)
		return weeks[w]


import calendar

class Solution:

	def getDayOfWeek(self, d, m, y):
		day = {0: 'Monday', 1: 'Tuesday', 2: 'Wednesday', 3: 'Thursday', 4: 'Friday', 5: 'Saturday', 6: 'Sunday'}
		day_num = calendar.weekday(y, m, d)
		return day[day_num]


import datetime

class Solution:

	def getDayOfWeek(self, d, m, y):
		days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
		a = datetime.datetime(y, m, d).weekday()
		return days[a]


class Solution:

	def getDayOfWeek(self, d, m, y):
		c = y // 100 + 1
		if y % 400 == 0 or (y % 4 == 0 and y % 100 != 0):
			if m == 1 or m == 2:
				o = -1
			else:
				o = 0
		else:
			o = 0
		d1 = {0: 'Sunday', 1: 'Monday', 2: 'Tuesday', 3: 'Wednesday', 4: 'Thursday', 5: 'Friday', 6: 'Saturday'}
		d2 = {1: 0, 2: 3, 3: 3, 4: 6, 5: 1, 6: 4, 7: 6, 8: 2, 9: 5, 10: 0, 11: 3, 12: 5}
		d3 = {1: 6, 2: 4, 3: 2, 0: 0}
		year = y % 100
		o += d + d2[m] + year + d3[c % 4] + year // 4
		return d1[o % 7]


import datetime

class Solution:

	def getDayOfWeek(self, d, m, y):
		cal = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
		x = datetime.date(y, m, d)
		return cal[x.weekday()]


import datetime
import calendar

class Solution:

	def getDayOfWeek(self, d, m, y):
		(day, month, year) = (d, m, y)
		dayNumber = calendar.weekday(year, month, day)
		days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
		return days[dayNumber]


import calendar

class Solution:

	def getDayOfWeek(self, d, m, y):
		days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
		date = calendar.weekday(y, m, d)
		return days[date]


import datetime
import calendar as c

class Solution:

	def getDayOfWeek(self, d, m, y):
		d = datetime.date(y, m, d)
		return c.day_name[d.weekday()]


import datetime

class Solution:

	def getDayOfWeek(self, d, m, y):
		WD = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
		D = datetime.date(y, m, d).weekday()
		return WD[D]


import datetime
from datetime import date

class Solution:

	def getDayOfWeek(self, d, m, y):
		day_name = datetime.date(int(y), int(m), int(d))
		return day_name.strftime('%A')


import datetime

class Solution:

	def getDayOfWeek(self, d, m, y):
		week = datetime.date(y, m, d)
		return week.strftime('%A')


import datetime

class Solution:

	def getDayOfWeek(self, d, m, y):
		s = {0: 'Sunday', 1: 'Monday', 2: 'Tuesday', 3: 'Wednesday', 4: 'Thursday', 5: 'Friday', 6: 'Saturday'}
		x = datetime.datetime(y, m, d)
		g = x.isoweekday() % 7
		return s[g]


class Solution:

	def getDayOfWeek(self, d, m, y):
		a = [0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5]
		b = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
		s = 0
		y -= m < 3
		t = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]
		z = (y + int(y / 4) - int(y / 100) + int(y / 400) + t[m - 1] + d) % 7
		return b[z]


import calendar

class Solution:

	def getDayOfWeek(self, d, m, y):
		weeks = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
		d = calendar.weekday(y, m, d)
		return weeks[d]
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(d, m, y) = map(int, input().split())
		ob = Solution()
		print(ob.getDayOfWeek(d, m, y))


class Solution:

	def getDayOfWeek(self, d, m, y):
		l = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
		t = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]
		y -= m < 3
		n = (y + y // 4 - y // 100 + y // 400 + t[m - 1] + d) % 7
		return l[n]
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(d, m, y) = map(int, input().split())
		ob = Solution()
		print(ob.getDayOfWeek(d, m, y))


class Solution:

	def getDayOfWeek(self, d, m, y):
		if m == 1 or m == 2:
			y = y - 1
			if m == 1:
				m = 11
			else:
				m = 12
		else:
			m = m - 2
		C = int(y / 100)
		Y = int(y % 100)
		weeks = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
		w = int((d + (2.6 * m - 0.2) - 2 * C + Y + int(Y / 4) + int(C / 4)) % 7)
		return weeks[w]
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(d, m, y) = map(int, input().split())
		ob = Solution()
		print(ob.getDayOfWeek(d, m, y))


import calendar

class Solution:

	def getDayOfWeek(self, d, m, y):
		weekday = calendar.weekday(y, m, d)
		dict = {'Monday': 0, 'Tuesday': 1, 'Wednesday': 2, 'Thursday': 3, 'Friday': 4, 'Saturday': 5, 'Sunday': 6}
		key_list = list(dict.keys())
		val_list = list(dict.values())
		return key_list[val_list.index(weekday)]
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(d, m, y) = map(int, input().split())
		ob = Solution()
		print(ob.getDayOfWeek(d, m, y))


import datetime
import calendar

class Solution:

	def getDayOfWeek(self, d, m, y):
		born = datetime.date(y, m, d)
		return born.strftime('%A')


import datetime

class Solution:

	def getDayOfWeek(self, d, m, y):
		week_days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
		day = datetime.date(y, m, d).weekday()
		return week_days[day]


import math

class Solution:

	def getDayOfWeek(self, d, m, y):
		days = ('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')
		t = [11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
		if m < 3:
			y -= 1
		c = y // 100
		w = (d + math.floor(2.6 * t[m - 1] - 0.2) - 2 * c + y % 100 + math.floor(y % 100 / 4) + math.floor(c / 4)) % 7
		return days[w]


import datetime

class Solution:

	def getDayOfWeek(self, d, m, y):
		week_num = datetime.date(y, m, d).weekday()
		weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
		return weekdays[week_num]


from datetime import date

class Solution:

	def getDayOfWeek(self, d, m, y):
		day = date(y, m, d).weekday()
		if day == 0:
			return 'Monday'
		elif day == 1:
			return 'Tuesday'
		elif day == 2:
			return 'Wednesday'
		elif day == 3:
			return 'Thursday'
		elif day == 4:
			return 'Friday'
		elif day == 5:
			return 'Saturday'
		else:
			return 'Sunday'


class Solution:

	def is_leap_year(self, year: int):
		if year % 4 == 0:
			if year % 100 == 0:
				if year % 400 == 0:
					return True
				else:
					return False
			else:
				return True
		else:
			return False

	def years_to_days(self, year: int):
		leap_years = year // 4 - year // 100 + year // 400 - 1
		return year * 365 + leap_years

	def month_to_days(self, year: int, month: int):
		extra_days = 1 if self.is_leap_year(year) else 0
		month_days = {1: 31, 2: 28 + extra_days, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31}
		return sum((d for (m, d) in month_days.items() if m <= month))
	DAYS = {0: 'Monday', 1: 'Tuesday', 2: 'Wednesday', 3: 'Thursday', 4: 'Friday', 5: 'Saturday', 6: 'Sunday'}

	def getDayOfWeek(self, d, m, y):
		week_day = (self.years_to_days(y - 1) + self.month_to_days(y, m - 1) + d) % 7
		return self.DAYS[week_day]


import datetime
import calendar

class Solution:

	def getDayOfWeek(self, d, m, y):
		date_val = datetime.date(y, m, d)
		return calendar.day_name[date_val.weekday()]


import datetime

class Solution:

	def getDayOfWeek(self, d, m, y):
		week = datetime.date(y, m, d).weekday()
		week_name = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
		k = week_name[week]
		return k


import datetime as dt

class Solution:

	def getDayOfWeek(self, d, m, y):
		x = dt.datetime(y, m, d)
		return x.strftime('%A')


import datetime

class Solution:

	def getDayOfWeek(self, d, m, y):
		day = ['', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
		return format(day[datetime.datetime(y, m, d).isoweekday()])


import datetime

class Solution:

	def getDayOfWeek(self, d, m, y):
		t = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]
		y -= m < 3
		week = (y + int(y / 4) - int(y / 100) + int(y / 400) + t[m - 1] + d) % 7
		if week == 0:
			return 'Sunday'
		elif week == 1:
			return 'Monday'
		elif week == 2:
			return 'Tuesday'
		elif week == 3:
			return 'Wednesday'
		elif week == 4:
			return 'Thursday'
		elif week == 5:
			return 'Friday'
		else:
			return 'Saturday'