LeetCode 2230: The Users That Are Eligible for Discount Solution

Master LeetCode problem 2230 (The Users That Are Eligible for Discount), 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.

2230. The Users That Are Eligible for Discount

Problem Explanation

Explanation:

We are given a list of integers representing the purchase amounts of users. Users are eligible for a discount if their purchase amount is greater than or equal to $100. We need to return a list of users who are eligible for a discount.

To solve this problem, we iterate through the list of purchase amounts and check if each amount is greater than or equal to $100. If it is, we add the index of that user to our result list.

  • Time complexity: O(n) where n is the number of users
  • Space complexity: O(1) if we ignore the space used for the result list

:

Solution Code

import java.util.ArrayList;
import java.util.List;

class Solution {
    public List<Integer> usersWithDiscount(List<Integer> purchaseAmounts) {
        List<Integer> result = new ArrayList<>();
        
        for (int i = 0; i < purchaseAmounts.size(); i++) {
            if (purchaseAmounts.get(i) >= 100) {
                result.add(i);
            }
        }
        
        return result;
    }
}

Try It Yourself

Loading code editor...

Related LeetCode Problems

Frequently Asked Questions

How to solve LeetCode 2230 (The Users That Are Eligible for Discount)?

This page provides optimized solutions for LeetCode problem 2230 (The Users That Are Eligible for Discount) 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 2230 (The Users That Are Eligible for Discount)?

The time complexity for LeetCode 2230 (The Users That Are Eligible for Discount) varies by solution. Check the detailed explanation section for specific complexities in Java, C++, and Python implementations.

Can I run code for LeetCode 2230 on DevExCode?

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

Back to LeetCode Solutions