At the arcade you play the levels in order; costs says how many coins each one takes, and you have coins. As soon as you can't pay for a level you stop, and skip the rest too. Write LevelsPlayed(costs, coins) to return how many levels you played.
LevelsPlayed([]int{3, 5, 4}, 10)→2LevelsPlayed([]int{2, 2}, 10)→2func LevelsPlayed(costs []int, coins int) intpackage main
func LevelsPlayed(costs []int, coins int) int {
played := 0
for _, c := range costs {
// your code here: not enough coins for this level? break
coins -= c
played++
}
return played
}
Run tries the examples. When they look right, Submit.