Over a million developers have joined DZone.

Code Puzzler: Favorite Seats

· DevOps Zone

Discover how to optimize your DevOps workflows with our cloud-based automated testing infrastructure, brought to you in partnership with Sauce Labs

Given an array of n rows numbered 0 to n-1, each of m seats 0 to m-1, where the cells have values True (meaning the seat is available) or False (meaning the seat is taken). A customer states that his favorite seat is at row x and seat y on that row.

If this seat is free, then the customer gets that seat. If it is taken, another seat is searched until a free seat has been found or it is clear that no free seat exist.

The search should start outwards from the preferred seat (x,y) in this fashion where 1 is the preferred seat, all 2's are second best two seats away, 3's are third best three seats away and so on.

3 3 3 3 3
3 2 2 2 3
3 2 1 2 3
3 2 2 2 3
3 3 3 3 3

Obviously the search should never go outside the array!


Download “The DevOps Journey - From Waterfall to Continuous Delivery” to learn learn about the importance of integrating automated testing into the DevOps workflow, brought to you in partnership with Sauce Labs.

Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}