LeetCode 1607: Sellers With No Sales
Problem Description
Explanation
Given a list of sellers and their corresponding sales, we need to find the sellers who have not made any sales. We can achieve this by iterating through the list of sales and keeping track of the sellers who have made at least one sale. Then, we can iterate through the list of all sellers and identify the ones who have not made any sales.
Algorithmic Idea
- Create a set to store sellers who have made at least one sale.
- Iterate through the list of sales and add the seller to the set.
- Iterate through the list of all sellers and check if the seller is not in the set of sellers who have made sales.
Time Complexity
The time complexity of this algorithm is O(n), where n is the total number of sellers.
Space Complexity
The space complexity of this algorithm is O(n), where n is the total number of sellers.
Solutions
import java.util.*;
class Solution {
public List<Integer> findSellersWithNoSales(List<Integer> sales, List<Integer> allSellers) {
Set<Integer> sellersWithSales = new HashSet<>();
for (int sale : sales) {
sellersWithSales.add(sale);
}
List<Integer> sellersWithNoSales = new ArrayList<>();
for (int seller : allSellers) {
if (!sellersWithSales.contains(seller)) {
sellersWithNoSales.add(seller);
}
}
return sellersWithNoSales;
}
}
Loading editor...