Skip to content

Instantly share code, notes, and snippets.

@McLarenCollege
Last active August 19, 2021 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McLarenCollege/565f1776fcd8ea4fd58572dc8f288082 to your computer and use it in GitHub Desktop.
Save McLarenCollege/565f1776fcd8ea4fd58572dc8f288082 to your computer and use it in GitHub Desktop.
Group Seats

Movie Theater Seating

A group of n friends are going to see a movie. They would like to find a spot where they can sit next to each other in the same row. A movie theater's seat layout can be represented as a 2-D matrix, where 0s represent empty seats and 1s represent taken seats.

[[1, 0, 0, 0, 1, 1, 1],
[1, 1, 1, 0, 1, 1, 1],
[1, 0, 1, 0, 1, 0, 1],
[1, 1, 0, 1, 1, 0, 1],
[1, 0, 1, 1, 1, 1, 1],
[1, 0, 1, 1, 0, 0, 0]]

Create a function that, given a seat layout and the number of friends n, returns the number of available spots for all n friends to sit together.

In the above example, if n = 3, there would be 2 spots (the first row and last row).

function groupSeats(theatre,friends){
// write your code here
}


console.log(groupSeats([
  [1, 0, 1, 0, 1, 0, 1],
  [0, 1, 0, 1, 0, 1, 0],
  [0, 0, 1, 1, 1, 1, 1],
  [1, 0, 1, 1, 0, 0, 1],
  [1, 1, 1, 0, 1, 0, 1],
  [0, 1, 1, 1, 1, 0, 0]
], 2));// 3

console.log(groupSeats([
  [1, 0, 1, 0, 1, 0, 1],
  [0, 1, 0, 0, 0, 0, 0],
], 4)); //2

console.log(groupSeats([
  [0, 0, 1, 0, 0, 0, 1],
  [0, 1, 0, 0, 0, 0, 0],
], 2)); //7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment