Find number of times every day occurs in a Year
Given a year .Your task is to find the number of every day in a year ie.number of Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday in that given year.
Input: 2019 Output: Monday-52 Tuesday-53 Wednesday-52 Thursday-52 Friday-52 Saturday-52 Sunday-52 Input: 2024 Output: Monday-53 Tuesday-53 Wednesday-52 Thursday-52 Friday-52 Saturday-52 Sunday-52
Observations: We have to make some key observations. The first one will be that there are at least 52 weeks in a year, so every day will occur at least 52 times in a year. As 52*7 is 364 so the day occurring on the 1st January of any year will occur 53 times and if the year is a leap year then the day on the 2nd January will also occur 53 times.
Approach: Create a list with size 7 and having an initial value of 52 as the minimum number of occurrences will be 52. Find the index of the first day. Calculate the number of days whose occurrence will be 53.
Below is the implementation.
Monday 52 Tuesday 52 Wednesday 52 Thursday 52 Friday 53 Saturday 53 Sunday 52