import java.util.*;
public class Solution {
    public static List<List<Integer>> transposeMatrix(List<List<Integer>> matrix) {

        List<Integer> ll = new ArrayList<Integer>();

        List<List<Integer>> finalMatrix = new ArrayList<List<Integer>>();

        int size=0;
        int matrixSize=matrix.size();
        int posInList=0;
        int numElementsInList=0;
        int counter=0;
        int i;
        int position=0;

//this gets number items in list
for (List<Integer> ee: matrix)
        {
            for (int k: ee)
            {
                numElementsInList++;
            }
            break;

        }

        //we will now go through each innerList element
        //This is simplest technique
        
        //we know the length innerList elements are identical
        //so sufficient to perform this
        for (int j=0; j<numElementsInList;j++)
        {
            System.out.println("--------Commencing transposing at index: " + position);
            /*
            //(step increase is numItemsInList)
            //we know for example, the inner loop indexes should be incrementing as such
            (0,2,4)  for  {1,4}, {2,5}, {3,6}

            //we know for example, the inner loop should be incrementing as such
            (0,3,6)  for  {1,4,7}, {2,5,8}, {3,6,9}
            */
            //ll.add(matrix.get(j));

        
        for (int k=0; k<matrixSize; k++)
        {
            System.out.println("IS IT HERE AFTER BREAK");            
            System.out.println("INNER LIST: " + matrix.get(k));

            //we now need to go throug each element in k
            
            //for (int l=0; l<numElementsInList;l++)
            for (int l: matrix.get(k))
            {
                //we know if l is equal to k
                //k is each index in numItemsInList
                //we will be storing these index values for all the List<Integer> 

                System.out.println("position: " + position);
                System.out.println("counter: " + counter);

                if (position==counter)
                {
                    System.out.println("EVER REACH");
                    ll.add(l);
                    System.out.println("CURRENT LIST: " + ll);
                    System.out.println("PERFORMING BREAK: " + "position: " + position + " counter: " + counter);
                    break;
                }
                
            }
            position++;

            //we need to set position back to 0
            //so that in next iteration, the value of l
            //will reflect the next Integer in List<Integer>
            //position=0;
            counter++;
        }

        
        position=1;
        counter=1;
        finalMatrix.add(ll);
        System.out.println("CURRENT TRANSFORMATION: " + finalMatrix);
        ll.clear();
        } //this is the end of the outer for loop

        return finalMatrix;

    }
}