Cody

Problem 2398. FIFA World Cup 2014 : Offside

This problem is about offside rule in football (soccer).

Input is a matrix with mostly zeros and a few 1, 2, 3 and 4s. A zero indicates empty space in the field. A 1 indicates a player from team A. A 3 indicates a player from team B. A 2 indicates a player from team A who is in possession of the ball. A 4 indicates a player from team B who is in possession of the ball. Players on the top and bottom rows indicate the goalkeepers of two teams. Determine if there is any player from either team who is in offside position and return true if yes. Complicated scenarios such as offside rule during passes or crosses are not considered (will be in the next problem). Someone will always be in possession of the ball.

Definition of offside (for the sake of this problem): Closest player (without having possession of the ball) to a goalkeeper must be from the same team of the goalkeeper.

Example:

input: 
x=[0 0 0 1 0 0 0;
   0 0 0 3 0 0 0;
   0 0 0 2 1 0 0;
   0 0 0 3 1 3 1;
   0 3 1 0 1 0 1;
   0 1 3 1 3 1 3;
   0 3 0 0 0 0 0;
   0 0 3 0 0 3 0;
   0 0 0 3 0 0 0];
Output : True

Player of team B in the second row is closer to the goal keeper of team A than any other defenders of team A and the ball is currently at the third row. So, it is offside and thus true.

Solution Stats

75.0% Correct | 25.0% Incorrect
Last solution submitted on Jun 30, 2019

Problem Comments

Recent Solvers10

Suggested Problems

More from this Author45