Facebook | Phone | Team Photo

I've been recently asked this question in an interview. Question is as follows:

Given heights of player of two football teams in array A and array B respectively. Now, you have to tell if you can arrange the team for photograph with following constraint.

One Team will be standing in one row (All players of one team must be together).
Height of player of one team standing in front should be lesser than the height of player of other team standing behind him.
Follow up question to this was, what if there are N teams what would be the maximum team K you can select for photograph such that they would follow the above constraints.

I came up with the solution for 2 team but couldn't think of solution for the follow up question.

Comments (8)