Microsoft Online Assessment (OA) - Day of week that is K days later

Given current day as day of the week and an integer K, the task is to find the day of the week after K days.

Example 1:

Input:

day = “Monday”

K = 3

Output: Thursday

Example 2:

Input:

day = “Tuesday”

K = 101

Output: Friday

Try it yourself

Implementation

1
1
def day_of_week(day: str, k: int) -> str:
2
-
    # WRITE YOUR BRILLIANT CODE HERE
2
+
    days = [
3
-
    return ''
3
+
        'Monday',
4
+
        'Tuesday',
5
+
        'Wednesday',
6
+
        'Thursday',
7
+
        'Friday',
8
+
        'Saturday',
9
+
        'Sunday',
10
+
    ]
11
+
    index = 0
12
+
    for i in range(len(days)):
13
+
        if days[i] == day:
14
+
            index = i
15
+
    return days[(index + k) % 7]
16
+
4
17
if __name__ == '__main__':
5
18
    day = input()
6
19
    k = int(input())
7
20
    res = day_of_week(day, k)
8
21
    print(res)