---
# System prepended metadata

title: LC 2643. Row With Maximum Ones
tags: [easy, leedcode, python]

---

# LC 2643. Row With Maximum Ones

### [Problem link](https://leetcode.com/problems/row-with-maximum-ones/)

###### tags: `leedcode` `python` `easy`

Given a <code>m x n</code> binary matrix <code>mat</code>, find the  **0-indexed**  position of the row that contains the  **maximum**  count of  **ones,**  and the number of ones in that row.

In case there are multiple rows that have the maximum count of ones, the row with the  **smallest row number**  should be selected.

Return an array containing the index of the row, and the number of ones in it.

**Example 1:** 

```
Input: mat = [[0,1],[1,0]]
Output: [0,1]
Explanation: Both rows have the same number of 1's. So we return the index of the smaller row, 0, and the maximum count of ones (1<code>)</code>. So, the answer is [0,1]. 
```

**Example 2:** 

```
Input: mat = [[0,0,0],[0,1,1]]
Output: [1,2]
Explanation: The row indexed 1 has the maximum count of ones <code>(2)</code>. So we return its index, <code>1</code>, and the count. So, the answer is [1,2].
```

**Example 3:** 

```
Input: mat = [[0,0],[1,1],[0,0]]
Output: [1,2]
Explanation: The row indexed 1 has the maximum count of ones (2). So the answer is [1,2].
```

 **Constraints:** 

- <code>m == mat.length</code>
- <code>n == mat[i].length</code>
- <code>1 <= m, n <= 100</code>
- <code>mat[i][j]</code> is either <code>0</code> or <code>1</code>.


## Solution 1
```python=
class Solution:
    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:
        m = [sum(i) for i in mat]
        max_idx = m.index(max(m))
        max_val = m[max_idx]
        
        return [max_idx, max_val]
```

>### Complexity
>m = mat.length
>n = mat[i].length
>|             | Time Complexity | Space Complexity |
>| ----------- | --------------- | ---------------- |
>| Solution 1  | O(mn)           | O(mn)            |

## Note
x
