Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Imagine you are at a baseball game and you are trying to pick the best seat out of a row of N seats. To
Imagine you are at a baseball game and you are trying to pick the best seat out of a row of N seats. To you, the best seat means the seat that is farthest away from any other people who are already seated in that row. Please give us a function to solve the problem using Python or R. Provide all code and output. The input should be a list of ints called "seats". This list has a 1 if the seat is taken and a 0 if it is empty. For example, if the 1st, 4th, and 7th seats are occupied, the input will be [1, 0, 0, 1, 0, 0, 1, 0, 0, 0]. Your goal is to find the seat index that is the farthest away from the next closest occupied seat, and return that seat's index. The input list is always ordered numerically. It is possible, given some inputs, to have 2 seats both be the farthest from any occupied seat. In this case, return the lower index. Here are some example inputs and their expected return value: Input -> [1, 0, 0, 1, 0, 0, 1, 0, 0, 0] returns -> 9 Input>[1, 0, 0, 0, 0, 0, 0, 0, 1, 0] returns -> 4 Input -> [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0] returns -> 0
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started