LeetCode 1821: Find Customers With Positive Revenue this Year
Problem Description
Explanation:
To solve this problem, we need to filter and return the names of customers who have made a positive revenue in the current year. We can achieve this by iterating through the given list of customers and checking if their revenue for the current year is greater than zero.
- Start by initializing an empty list to store the names of customers with positive revenue.
- Iterate through each customer in the input list.
- For each customer, check if their revenue for the current year is greater than zero.
- If the revenue is positive, add the customer's name to the result list.
- Finally, return the list of names of customers with positive revenue.
Time Complexity:
The time complexity of this approach is O(n) where n is the number of customers in the input list.
Space Complexity:
The space complexity is O(1) as we are only storing the names of customers with positive revenue.
: :
Solutions
import java.util.ArrayList;
import java.util.List;
class Solution {
public List<String> findCustomersWithPositiveRevenueThisYear(List<String> customers, List<Integer> revenues) {
List<String> result = new ArrayList<>();
for (int i = 0; i < customers.size(); i++) {
if (revenues.get(i) > 0) {
result.add(customers.get(i));
}
}
return result;
}
}
Loading editor...