Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Design Operation And Evaluation Of Mobile Communications

Authors: Gavriel Salvendy ,June Wei

1st Edition

3030770249, 978-3030770242

More Books

Students also viewed these Programming questions

Question

=+ Define product mix, product extension, and product enhancement.

Answered: 1 week ago

Question

4 potential pitfalls in using accounting data in decision making

Answered: 1 week ago

Question

Identify typical EEO enforcement and compliance requirements.

Answered: 1 week ago