Over a million developers have joined DZone.
Platinum Partner

Code Puzzler: Favorite Seats

· DevOps Zone

The DevOps Zone is brought to you in partnership with HPE.  Learn about the seven KPI’s that create the foundation of DevOps metrics and how it continues to evolve as the DevOps Methodology becomes more engrained in enterprises.  

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!


The DevOps Zone is brought to you in partnership with HPE.  Discover the Top 5 predictions for DevOps and the central role they will play as enterprises begin to modernize legacy applications.

Topics:

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

{{ parent.tldr }}

{{ parent.urlSource.name }}