You are viewing a single comment's thread. Return to all comments →
Solution in go
func fairRations(B []int32) string { oddIndex := -1 totalBreads := int32(0) for i := 0; i < len(B); i++ { if B[i]%2 > 0 { if oddIndex < 0 { oddIndex = i continue } totalBreads += int32((i - oddIndex) * 2) oddIndex = -1 } } if oddIndex >= 0 { return "NO" } return fmt.Sprintf("%d", totalBreads) }
Seems like cookies are disabled on this browser, please enable them to open this website
Fair Rations
You are viewing a single comment's thread. Return to all comments →
Solution in go