1142. Repeated Rows
A weather station logs one row of readings per sensor, and every row has the same number of columns. During a bad upload some rows were pasted twice. Given the matrix grid, return the 0-based indices, in ascending order, of every row that is an exact copy (same values in the same positions) of some row with a smaller index. The first appearance of a row is never reported, even if that row repeats many times later. Rows that hold the same numbers in a different order are different rows. If no row repeats, return an empty array.
The grid has m rows and n columns, with 1 <= m <= 100, 1 <= n <= 50 and every value between -10^9 and 10^9. Aim for O(m * n) time and O(m * n) space by hashing every row.
Example 1
- Input:
- grid = [[1,2],[3,4],[1,2],[1,2]]
- Output:
- [2,3]
- Explanation:
Rows 2 and 3 both equal row 0, so the answer is [2, 3].
Example 2
- Input:
- grid = [[5,6,7],[7,6,5],[5,6,7]]
- Output:
- [2]
- Explanation:
Row 1 has the same numbers as row 0 in reverse order, so only row 2 is a copy.
Example 3
- Input:
- grid = [[1],[2],[3]]
- Output:
- []
- Explanation:
All rows are different, so the answer is empty.
Constraints
1 ≤ m ≤ 100
1 ≤ n ≤ 50
-109 ≤ grid[i][j] ≤ 109
How this problem is judged
- Answers
- Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.
Expected complexity
- Time
- O(m * n)
- Space
- O(m * n)