44 lines
876 B
Go
44 lines
876 B
Go
//go:build !solution
|
|
|
|
package hotelbusiness
|
|
|
|
import "math"
|
|
|
|
type Guest struct {
|
|
CheckInDate int
|
|
CheckOutDate int
|
|
}
|
|
|
|
type Load struct {
|
|
StartDate int
|
|
GuestCount int
|
|
}
|
|
|
|
func ComputeLoad(guests []Guest) []Load {
|
|
if len(guests) == 0 {
|
|
return []Load{}
|
|
}
|
|
minDate, maxDate := math.MaxInt, math.MinInt
|
|
loadsNoEmptyDays := make(map[int]int)
|
|
for _, guest := range guests {
|
|
if guest.CheckInDate < minDate {
|
|
minDate = guest.CheckInDate
|
|
}
|
|
if guest.CheckOutDate > maxDate {
|
|
maxDate = guest.CheckOutDate
|
|
}
|
|
for i := guest.CheckInDate; i < guest.CheckOutDate; i++ {
|
|
loadsNoEmptyDays[i]++
|
|
}
|
|
}
|
|
loads, prevGuestCount := make([]Load, 0), 0
|
|
for i := minDate; i <= maxDate; i++ {
|
|
guestCount := loadsNoEmptyDays[i]
|
|
if prevGuestCount == guestCount {
|
|
continue
|
|
}
|
|
loads = append(loads, Load{i, guestCount})
|
|
prevGuestCount = guestCount
|
|
}
|
|
return loads
|
|
}
|