LeetCode 1821: Find Customers With Positive Revenue this Year Solution

Master LeetCode problem 1821 (Find Customers With Positive Revenue this Year), 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.

1821. Find Customers With Positive Revenue this Year

Problem Explanation

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.

: :

Solution Code

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;
    }
}

Try It Yourself

Loading code editor...

Related LeetCode Problems

Frequently Asked Questions

How to solve LeetCode 1821 (Find Customers With Positive Revenue this Year)?

This page provides optimized solutions for LeetCode problem 1821 (Find Customers With Positive Revenue this Year) 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 1821 (Find Customers With Positive Revenue this Year)?

The time complexity for LeetCode 1821 (Find Customers With Positive Revenue this Year) varies by solution. Check the detailed explanation section for specific complexities in Java, C++, and Python implementations.

Can I run code for LeetCode 1821 on DevExCode?

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

Back to LeetCode Solutions