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 Librato.  Check out Librato's whitepaper on Selecting a Cloud Monitoring Solution.

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!


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

{{ parent.tldr }}

{{ parent.urlSource.name }}