curriculum/challenges/english/blocks/daily-coding-challenges-python/69306364df283fcaff2e1ad7.md
Given a 4x2 matrix (array of arrays) representing the seating arrangement for a meal, determine how many seats a left-handed person can sit at.
In the given matrix:
"R" is a seat occupied by a right-handed person."L" is a seat occupied by a left-handed person."U" is an unoccupied seat.For example, in the given matrix:
[
["U", "R", "U", "L"],
["U", "R", "R", "R"]
]
The top-left seat is cannot be sat in because there's a right-handed person to the left. The other two open seats can be sat in because there isn't a right-handed person to the left.
find_left_handed_seats([["U", "R", "U", "L"], ["U", "R", "R", "R"]]) should return 2.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(find_left_handed_seats([["U", "R", "U", "L"], ["U", "R", "R", "R"]]), 2)`)
}})
find_left_handed_seats([["U", "U", "U", "U"], ["U", "U", "U", "U"]]) should return 8.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(find_left_handed_seats([["U", "U", "U", "U"], ["U", "U", "U", "U"]]), 8)`)
}})
find_left_handed_seats([["U", "R", "U", "R"], ["L", "R", "R", "U"]]) should return 0.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(find_left_handed_seats([["U", "R", "U", "R"], ["L", "R", "R", "U"]]), 0)`)
}})
find_left_handed_seats([["L", "U", "R", "R"], ["L", "U", "R", "R"]]) should return 1.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(find_left_handed_seats([["L", "U", "R", "R"], ["L", "U", "R", "R"]]), 1)`)
}})
find_left_handed_seats([["U", "R", "U", "U"], ["U", "U", "L", "U"]]) should return 5.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(find_left_handed_seats([["U", "R", "U", "U"], ["U", "U", "L", "U"]]), 5)`)
}})
def find_left_handed_seats(table):
return table
def find_left_handed_seats(table):
available_seats = 0
top_row, bottom_row = table
for i in range(len(top_row)):
if top_row[i] == "U":
if i == len(top_row) - 1:
available_seats += 1
elif top_row[i + 1] != "R":
available_seats += 1
for i in range(len(bottom_row)):
if bottom_row[i] == "U":
if i == 0:
available_seats += 1
elif bottom_row[i - 1] != "R":
available_seats += 1
return available_seats