Introduction
Suppose you have a list of lists of integers (or any objects really, but let's stick to integers for simplicity). The lists may be of different lengths, and some of them may be empty. Let's write the lists in a tabular format:
[[ 1, 2, 3, 4, 5],
[ 6, 7],
[ 8, 9, 10, 11],
[],
[12, 13, 14],
[15, 16, 17, 18]]
This table has 5 vertical columns, containing the numbers 1, 6, 8, 12, 15
, 2, 7, 9, 13, 16
, 3, 10, 14, 17
, 4, 11, 18
, and 5
.
If we reverse each column, we obtain the lists 15, 12, 8, 6, 1
, 16, 13, 9, 7, 2
, 17, 14, 10, 3
, 18, 11, 4
, and 5
.
Let's plug those numbers back into the columns of the table while keeping the lengths of the rows the same as before:
[[15, 16, 17, 18, 5],
[12, 13],
[ 8, 9, 14, 11],
[],
[ 6, 7, 10],
[ 1, 2, 3, 4]]
Your task is to implement this operation.
Input and output
Your input is a list of lists of nonnegative integers, representing the rows. The rows may have different lengths, and some of them may be empty. There will always be at least one row. Your output is the result of reversing each column, as detailed above. Input and output may be in any reasonable format.
The lowest byte count in each language wins. Standard code-golf rules apply.
Test cases
[[]] -> [[]]
[[],[]] -> [[],[]]
[[8,5,1]] -> [[8,5,1]]
[[1,200],[0,3]] -> [[0,3],[1,200]]
[[],[3,9],[1],[]] -> [[],[1,9],[3],[]]
[[],[5,8,7],[0,6,5,7,1]] -> [[],[0,6,5],[5,8,7,7,1]]
[[1,8,5],[7,5,4],[],[1]] -> [[1,5,4],[7,8,5],[],[1]]
[[],[],[2],[],[31],[],[5],[],[],[],[7]] -> [[],[],[7],[],[5],[],[31],[],[],[],[2]]
[[1,10,100,1000],[2,20,200],[3,30],[4],[5,50,500],[6,60],[7]] -> [[7,60,500,1000],[6,50,200],[5,30],[4],[3,20,100],[2,10],[1]]
[[8,4],[3,0,4,8,1],[8],[0,8],[9,7,1,6],[3,8,1,9,5]] -> [[3,8],[9,7,1,9,5],[0],[8,8],[3,0,1,6],[8,4,4,8,1]]
[[3,9,3],[5],[1],[3,5],[9,0,6,2],[1,3],[4,9,2],[6,6,7,8,7]] -> [[6,6,7],[4],[1],[9,9],[3,3,2,8],[1,0],[5,5,6],[3,9,3,2,7]]
[[8,5,6],[3,5,2,4,9],[4,3,8,3,7],[6,1,1],[1,8,9,9],[9,1,2],[8,7]] -> [[8,7,2],[9,1,9,9,7],[1,8,1,3,9],[6,1,8],[4,3,2,4],[3,5,6],[8,5]]
[[2,4],[1,4],[0,8,7,3],[4,9,2,5],[2,8,0],[0,8,3],[7,3,1],[],[3,3,7,8]] -> [[3,3],[7,3],[0,8,7,8],[2,8,1,5],[4,9,3],[0,8,0],[1,4,2],[],[2,4,7,3]]
[[1,9],[3],[2,4,5]] -> [[2,4],[3,null],[1,9,5]]
) \$\endgroup\$