package q2483 func bestClosingTime(customers string) int { numY := 0 for i := range len(customers) { if customers[i] == 'Y' { numY++ } } minCloseHour := 0 minPenalty := numY penalty := numY for i := range len(customers) { // close at (i + 1)th hour switch customers[i] { case 'N': penalty++ case 'Y': penalty-- } if penalty < minPenalty { minPenalty = penalty minCloseHour = i + 1 } } return minCloseHour } var _ = bestClosingTime