Remove Duplicate Rows
~15 mincode completion
Implement remove_duplicate_rows(X) that returns a 2D NumPy array of unique rows in first-appearance order.
Examples
One duplicate at index 2 removed: output shape is (3, 2)
- Input
- remove_duplicate_rows([[1, 2], [3, 4], [1, 2], [5, 6]])
- shape of result
- [3, 2]
First row of deduplicated output is correct
- Input
- remove_duplicate_rows([[1, 2], [3, 4], [1, 2], [5, 6]])
- first row of result
- [1, 2]
Three occurrences of [1,1] collapsed to one: output shape is (3, 2)
- Input
- remove_duplicate_rows([[1, 1], [2, 2], [1, 1], [1, 1], [3, 3]])
- shape of result
- [3, 2]
Hints
Hint 1
Build the result up as you go, then return it.
Hint 2
Watch for this: used np unique axis 0 which sorts output.
Requirements
X: 2D array of shape (n, d)Return 2D array with duplicate rows removed, preserving original order.
Constraints
Allowed library: NumPy only
Time limit: 200 ms, Memory: 64 MB
Where this shows up
~15 min
••••••••••••••••
8 employers weight this skill
2 health and bio companies, 2 AI product companies, 1 defense company, 1 enterprise vendor, 1 quant fund, 1 big tech firm. Top match scores 87.
Python
import numpy as np
def remove_duplicate_rows(X: np.ndarray) -> np.ndarray:
"""
Remove duplicate rows, keeping the first occurrence of each unique row.
Args:
X: 2D array of shape (n, d)
Returns:
2D array with duplicate rows removed, preserving original order.
"""
# YOUR CODE HERE
pass