Given a Matrix, the task is to write a Python program to get the count frequency of its rows lengths.
Input : test_list = [[6, 3, 1], [8, 9], [2], [10, 12, 7], [4, 11]]
Output : {3: 2, 2: 2, 1: 1}
Explanation : 2 lists of length 3 are present, 2 lists of size 2 and 1 of 1 length is present.
Input : test_list = [[6, 3, 1], [8, 9], [10, 12, 7], [4, 11]]
Output : {3: 2, 2: 2}
Explanation : 2 lists of length 3 are present, 2 lists of size 2.
In this we check for each row length, if length has occurred in the memorize dictionary, then the result is incremented or if a new size occurs, the element is registered as new.
OutputThe original list is : [[6, 3, 1], [8, 9], [2], [10, 12, 7], [4, 11]]
Row length frequencies : {3: 2, 2: 2, 1: 1}
In this, map() and len() get the lengths of each sublist in the matrix, Counter is used to keep the frequency of each of the lengths.
OutputThe original list is : [[6, 3, 1], [8, 9], [2], [10, 12, 7], [4, 11]]
Row length frequencies : {1: 1, 2: 2, 3: 2}
OutputThe original list is : [[6, 3, 1], [8, 9], [2], [10, 12, 7], [4, 11]]
Row length frequencies : {1: 1, 2: 2, 3: 2}
OutputThe original list is : [[6, 3, 1], [8, 9], [2], [10, 12, 7], [4, 11]]
Row length frequencies : {3: 2, 2: 2, 1: 1}
Time complexity: O(n), where n is the length of test_list.
Auxiliary space: O(k), where k is the number of distinct row lengths in test_list.