using System.Collections.Generic;
public static void Main()
var employeeVacationOne = new EmployeeVacationDetails("Vince", new DateTime(2021, 5, 25), new DateTime(2021, 6, 20));
var employeeVacationTwo = new EmployeeVacationDetails("Jennifer", new DateTime(2021, 2, 1), new DateTime(2021, 2, 14));
var employeeVacationThree = new EmployeeVacationDetails("Vince", new DateTime(2021, 10, 5), new DateTime(2021, 10, 15));
var employeeVacationFour = new EmployeeVacationDetails("Sam", new DateTime(2021, 1, 11), new DateTime(2021, 1, 15));
var employeeVacationFive = new EmployeeVacationDetails("John", new DateTime(2021, 1, 11), new DateTime(2021, 1, 30));
var orgVacation = new OrganizationVacationsManagement();
orgVacation.addVacation(employeeVacationOne);
orgVacation.addVacation(employeeVacationTwo);
orgVacation.addVacation(employeeVacationThree);
orgVacation.addVacation(employeeVacationFour);
orgVacation.addVacation(employeeVacationFive);
Console.WriteLine("List of days when no employee is having vacation:");
foreach(var day in orgVacation.GetDatesWhenNoEmployeesAreOnVacation())
Console.WriteLine(day.Date);
public record EmployeeVacationDetails
public string EmployeeName { get; }
public DateTime DateOfFirstVacationDay { get; }
public DateTime DateOfLastVacationDay { get; }
public EmployeeVacationDetails(string employeeName, DateTime dateOfFirstVacationDay, DateTime dateOfLastVacationDay)
if (dateOfFirstVacationDay.Year == 2021 && dateOfLastVacationDay.Year == 2021)
EmployeeName = employeeName;
DateOfFirstVacationDay = dateOfFirstVacationDay;
DateOfLastVacationDay = dateOfLastVacationDay;
throw new ArgumentException($"You can only add vacation records of year 2021");
public double GetEmployeeVacationLength()
return (DateOfLastVacationDay - DateOfFirstVacationDay).Days + 1;
public IEnumerable<DateTime> GetAllEmployeeVacationDates()
return Enumerable.Range(0, DateOfLastVacationDay.Subtract(DateOfFirstVacationDay).Days + 1)
.Select(day => DateOfFirstVacationDay.AddDays(day));
public class OrganizationVacationsManagement
private List<EmployeeVacationDetails> _employeeVacations;
public OrganizationVacationsManagement()
_employeeVacations = new List<EmployeeVacationDetails>();
public void addVacation(EmployeeVacationDetails vacation)
_employeeVacations.Add(vacation);
public double GetAverageVacationLengthOfOrganization()
return _employeeVacations.Average(employee => employee.GetEmployeeVacationLength());
public IEnumerable<(string, double)> GetAverageVacationLengthOfEachEmployee()
var employeeVacationAverage = _employeeVacations.GroupBy(employee => employee.EmployeeName,
employeeVacation => employeeVacation.GetEmployeeVacationLength())
.Select(employeVacationAvg => new
employeeName = employeVacationAvg.Key,
avgVacationVacationLength = employeVacationAvg.Average()
foreach(var employee in employeeVacationAverage)
yield return (employee.employeeName, employee.avgVacationVacationLength);
public IEnumerable<(int, int)> GetNumberOfEmployeesOnVacationByEachMonth()
var months = Enumerable.Range(1,12).ToList();
foreach(var month in months)
yield return (month, _employeeVacations.Count(vacation => vacation.DateOfFirstVacationDay.Month == month
|| vacation.DateOfLastVacationDay.Month == month));
public IEnumerable<DateTime> GetDatesWhenNoEmployeesAreOnVacation()
var startOfYearDate = new DateTime(2021, 01, 01);
var endOfYearDate = new DateTime(2021, 12, 31);
var allDatesOfYear = Enumerable.Range(0, endOfYearDate.Subtract(startOfYearDate).Days + 1)
.Select(day => startOfYearDate.AddDays(day));
return allDatesOfYear.Except(_employeeVacations.SelectMany(employee => employee.GetAllEmployeeVacationDates()
public bool DoDatesOfEmployeeVacationIntersect()
var test = _employeeVacations.GroupBy(employee => employee.EmployeeName, vacationDates => (vacationDates.DateOfFirstVacationDay, vacationDates.DateOfLastVacationDay));