LeetCode 2882: Drop Duplicate Rows Solution

Master LeetCode problem 2882 (Drop Duplicate Rows), a easy challenge, with our optimized solutions in Java, C++, and Python. Explore detailed explanations, test your code in our interactive editor, and prepare for coding interviews.

2882. Drop Duplicate Rows

Easy

Problem Explanation

Explanation

To solve this problem, we can use a HashSet to keep track of the unique emails encountered so far. We iterate through the DataFrame and check if the current row's email is already in the HashSet. If it is not present, we add the email to the HashSet and keep that row in the final result. If the email is already in the HashSet, we skip that row as it is a duplicate.

  • Time complexity: O(n) where n is the number of rows in the DataFrame
  • Space complexity: O(n) for the HashSet

Solution Code

import java.util.HashSet;
import java.util.List;

class Solution {
    public List<List<Object>> dropDuplicateRows(List<List<Object>> customers) {
        HashSet<String> uniqueEmails = new HashSet<>();
        List<List<Object>> result = new ArrayList<>();
        
        for (List<Object> row : customers) {
            String email = (String) row.get(2);
            if (!uniqueEmails.contains(email)) {
                uniqueEmails.add(email);
                result.add(row);
            }
        }
        
        return result;
    }
}

Try It Yourself

Loading code editor...

Frequently Asked Questions

How to solve LeetCode 2882 (Drop Duplicate Rows)?

This page provides optimized solutions for LeetCode problem 2882 (Drop Duplicate Rows) in Java, C++, and Python, along with a detailed explanation and an interactive code editor to test your code.

What is the time complexity of LeetCode 2882 (Drop Duplicate Rows)?

The time complexity for LeetCode 2882 (Drop Duplicate Rows) varies by solution. Check the detailed explanation section for specific complexities in Java, C++, and Python implementations.

Can I run code for LeetCode 2882 on DevExCode?

Yes, DevExCode provides an interactive code editor where you can write, test, and run your code for LeetCode 2882 in Java, C++, or Python.

Back to LeetCode Solutions