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]) |
Output
Wednesday
This approach requires O(K) time complexity
Auxiliary Space: O(1)
Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!