Codey and Sunday

https://www.hackerrank.com/contests/codenection-2024-test/challenges/cn24-test2

Question

Codey wanted to take a break and relax, and it wonder how many days are left until the next Sunday.

Input Format

The first line is a string s , the current day of the week.

Constraints

s is Monday to Saturday.

Output Format

Output an integer, the number of days from the given day until the next Sunday.

Sample Inputs:

Input

Wednesday

Output

4

Solution - Dictionary Lookup

Create a list which stores all the values of Sunday to Saturday:

Dictionary
days = ["Sunday", "Monday", ... , "Saturday"]

Then, receive the input, lookup with the index based on Input, then use 7 to subtract that index to get the answer. Simple.

Here's the solution:

days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]

print((7 - days.index(input())))

Last updated