17
3
Given a non-empty matrix of non-negative integers, answer which unique rows contribute most to the sum total of elements in the matrix.
Answer by any reasonable indication, for example a mask of the unique rows order of appearance (or sort order), or indices (zero- or one- based) of those, or a submatrix consisting of the rows (in any order) or some kind of dictionary construct… — but do explain it!
Examples
[[1,2,3],[2,0,4],[6,3,0],[2,0,4],[6,3,0],[2,0,4]]
:
The unique rows are [1,2,3]
, [2,0,4]
, and [6,3,0]
each respectively contributing 6, 6, and 9 each time they occur. However, they occur once, thrice and twice respectively, so all of their respective occurrences contribute 6, 18, and 18 to the total (42), so the latter two rows are the ones that contribute most. Valid answers are therefore:
[false,true,true]
mask in appearance/sort order or
[1,2]
/[2,3]
zero/one-based indices of the above or
[[2,0,4],[6,3,0]]
the actual rows
⋮
[[1,2],[3,1],[2,3],[1,2],[3,1],[2,3],[1,2]]
[false,false,true]
(appearance order) / [false,true,false]
(sort order)
[2]
/[3]
(appearance order) / [1]
/[2]
(sort order)
[[2,3]]
⋮
3Woha, that is short. – Adám – 2018-12-31T16:44:44.083