import java.util.*;
public class Solution {
public static boolean canSeeStage(int[][] seats) {


int rowNumber=0;
int seatNumber=0;
int count=0;
int [] frontRow;

   //the logic below checks each theater row from the front
   //and it gets all the people sitting in that row
   //it does this front => back
   //but we know no comparisons are made

   //we know it has to make a comparison with the row in front.
   //if there is no height violation, we no longer are concerned about being two rows apart...
   //we can only make a comparison on row two...
   //and we know the front row data is lost.... unless we keep a copy....

        for (int[] row: seats)  //this will go through each row in the theater
        {
            
            rowNumber++;
            System.out.println("ROW NUMBER IN THEATER: " + rowNumber);
            	    

            for (int s: row) //this will go through each seat in each row
            {
                seatNumber++;
                
                if (rowNumber>=2)
                {
                    //keeps a copy of the front row only once reached row 2 in theater
                    frontRow = new int [row.length];  //initialising here provides contingency if theater is not uniform row seats

                    do
                    {
                        frontRow[count]=row[count];
                        count++;

                    }while (count<row.length);

                    seatNumber=0;   //we set seats back to 0 on new row
                    count=0;                    

                    System.out.println("NOW CHECKING FOR AUDIENCE IN FRONT: " + "(seat: " + seatNumber+")");
                    //At this point we also need to assume that each row in theater has
                    //same number of seats
                    //we know be default, array elements have default value of 0

                    //we now compare against row in front 
                    // need to remember at this point, still in a triple nested loop
                    //logic as follows

                    //for each row, for first seat in the row, for all seats in frontRow
                    //this logic is flawed!!!!
                    //it will compare each seat in the row behind to all the seats in the row in front!!


                    for (int m: frontRow)
                    {
                        //seat is strictly higher
                        //this is a common mistake which I had completely forgotten
                        //if there is nobody seated in a row in front, it will take a default array value 0...
                        //so performing   //if (m>s)  will be totally incorrect
                        //we have to check if the person in row behind is taller!!
                        //and of course if there is nobody sitting on row behind, it is not a concern!

                        if (s>m)
                        {
                            System.out.println("Person in row: " + rowNumber + "(seat number:" + (m)+")" + "is obstructed by  row: " + (rowNumber-1) + "(seat number:" + m+")");
                            return false;   //
                        }
                    }
                }
            }
        }
    
    return true;    //all seats can see in front of it  
    }
}