Hi everyone,
Today, I’m going to continue the series of questions to be asked during a technical interview. This time, we are dealing more with a logical question and one feasible for almost all programming languages found on this planet.
Let’s start. You are dealing with two dates: **DATE_START**
and **DATE_END**
(**DATE_START <= DATE_END**
) and a method **getWeekDay**
which returns the day of the week as an integer, where Monday is 0 and Sunday is 6, for a given date. **getWeekDay**
method is already implemented and tested.
Can you implement a method for deciding if between **DATE_START**
and **DATE_END**
there is a full weekend included, using only calls to **getWeekDay**
(no other APIs are allowed)? A full weekend means at least one Saturday and one Sunday included.
Examples:
DATE_START = 25.05.2020
,DATE_END = 30.05.2020
. The method returns False.DATE_START = 25.05.2020
,DATE_END = 06.06.2020
. The method returns True.DATE_START = 30.05.2020
,DATE_END = 31.05.2020
. The method returns True.
The idea is to avoid using a loop to iterate over all days between **DATE_START**
and **DATE_END**
to mark ones from weekend. It’s possible to implement an algorithm without using a loop
Happy coding!