Kodewick
Start learning →
Mini challenge←→0 / 70

A row for friends

#024Mini challengeLoopsStrings7 min

The cinema seat map has one string per row: . is a free seat, x is taken. There are need of you and you want the same row (not necessarily side by side). Write RowForFriends(rows, need) to return the number of the first row with enough free seats (counting from 1), or 0 if none has.

Examples
RowForFriends([]string{"xx.x", "..x.", "...."}, 3)→2
RowForFriends([]string{"xxx", "x.x"}, 2)→0
The functionfunc RowForFriends(rows []string, need int) int
main.go
package main

func RowForFriends(rows []string, need int) int {
	for i, row := range rows {
		free := 0
		// your code here: range over the seats in this row, adding 1 to free for each '.'
		// your code here: enough free seats? return the row number
	}
	return 0
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.