# Maximum Maxima!

### J, 27 bytes

```
((I.@:=;])>./)@(+/@:=>./"1)
```

This is a monadic verb, used as follows in the case of the second example:

```
f =: ((I.@:=;])>./)@(+/@:=>./"1)
m =: 3 2 $ 7 93 69 35 77 77
f m
+---+-+
|0 1|1|
+---+-+
```

The output consists of two boxes, and uses 0-based indexing. Try it here!

### Explanation

```
((I.@:=;])>./)@(+/@:=>./"1) Input is m.
( )@( ) Composition: apply right hand side, then left hand side.
>./"1 Take maximum of each row of m.
= Replace row maxima by 1 and other values by 0,
+/@: then take sum (number of maxima) on each column.
The result is the array of number of row maxima in each column.
>./ Compute the maximum of this array
( ;]) and put it in a box with
I.@:= the indices of those entries that are equal to it.
```

## Pyth, ~~20~~ ~~19~~ 17 bytes

1 byte thanks to @Suever.

1 byte thanks to @Jakube.

```
{MC.MhZrSsxLeSdQ8
```

Test suite.

Output is 0-indexed.

Order is reversed.

### All inputs

```
[[7,93],[69,35],[77,30]]
[[7,93],[69,35],[77,77]]
[[1,2,3,4],[5,6,7,8]]
[[16,2,3,13],[5,11,10,8],[9,7,6,12]]
[[1,1,1,1]]
[[25,6,13,25]]
[[1],[2],[3],[4]]
[[100]]
```

### All outputs

```
[[2], [0]]
[[2], [0, 1]]
[[2], [3]]
[[1], [0, 1, 3]]
[[1], [0, 1, 2, 3]]
[[1], [0, 3]]
[[4], [0]]
[[1], [0]]
```

### How it works

```
{MC.MhZrSsxLeSdQ8
Q Yield input.
L For each array in input (as d):
eSd Yield maximum of d.
x Yield the 0-indexed indices of the maximum in d.
s Flatten.
S Sort.
r 8 Run-length encoding.
Now the array is:
[number of maxima in column, index of column]
for all the columns
.MhZ Yield the sub-arrays whose first element is maximum.
The first element of each sub-array
is "number of maxima in column".
Now the array is:
[number of maxima in column, index of column]
for all the required columns
C Transpose.
Now the array is:
[[number of maxima in each column],
[index of each required column]]
Note that every element in the
first sub-array is the same.
{M Deduplicate each.
```

## MATL, 17 bytes

```
vH3$X>G=XstX>tb=f
```

The first output is the max number of maxima and the second output is the columns in which this occured (1-based indexing).

**Try it Online!**

**Explanation**

```
v % Vertically concatenate everything on the stack (nothing), yields []
% Implicitly grab the input
H % Push the number 2 to the stack
3$X> % Compute the maximum value of each row (along the second dimension)
G % Explicitly grab input again
= % Compare each row of the input to the row-wise max (automatically broadcasts).
Xs % Sum the number of matches in each column
t % Duplicate the array
X> % Determine the max number of maxima in all columns
t % Duplicate this value
b=f % Find the index of the columns which had the maximum number of maxima
% Implicitly display stack contents
```