Content has been removed on Author’s request.
Using Naive Approach:
Approach:
One approach to find the day of the week after K days from a given day is to use a brute-force method where we add K days to the given day and then find the corresponding day of the week.
Algorithm:
Input the day and K
Add K days to the given day
Find the corresponding day of the week using the modulus operator (%)
Return the day of the week
Python3
days_of_week = [ "Sunday" , "Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday" , "Saturday" ] day = "Monday" K = 100 new_day = (days_of_week.index(day) + K) % 7 print (days_of_week[new_day]) |
Wednesday
This approach requires O(K) time complexity
Auxiliary Space: O(1)
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!