Kodewick
Start learning →
Mini challenge←→0 / 60

Seats for two

#056Mini challengevectorLoops6 min

In a row of cinema seats, taken[i] is true if someone is sitting there. Two friends want to sit together. Write seats_for_two(taken) to return every seat number where that seat and the one to its right are both free. Seats are numbered from 1 (taken[0] is seat 1).

Examples
seats_for_two({false, false, true, false})→[1]
seats_for_two({false, false, false})→[1, 2]
The functionvector<int> seats_for_two(const vector<bool> &taken)
main.cpp
#include <vector>
using namespace std;

vector<int> seats_for_two(const vector<bool> &taken) {
    vector<int> starts;
    for (int i = 0; i + 1 < (int)taken.size(); i++) {
        // your code here: if this one and the next are free, save the seat number
    }
    return starts;
}
Ctrl + Enter runs too
Result

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