Code Logo

Count Low Stock Items

Published at19 Apr 2026
Easy 0 views
Like0

This problem is based on a simple store inventory check. You have a list of stock quantities, and you want to know how many items are running low.

An item counts as low stock if its quantity is smaller than the given threshold. The answer should be the number of items that meet that rule.

For example, if the stock list is [12, 3, 7, 2] and the threshold is 5, then the answer is 2. Only 3 and 2 are below the threshold.

So the task is to scan the list, count the quantities that are too low, and return that count.

Example Input & Output

Example 1
Input
stock = [12, 3, 7, 2], threshold = 5
Output
2
Explanation

Only 3 and 2 are below the threshold.

Example 2
Input
stock = [6, 6, 6], threshold = 5
Output
0
Explanation

None of the items are below the threshold.

Example 3
Input
stock = [], threshold = 10
Output
0
Explanation

With no items in the list, the low-stock count stays 0.

Algorithm Flow

Recommendation Algorithm Flow for Count Low Stock Items
Recommendation Algorithm Flow for Count Low Stock Items

Solution Approach

A clean way to solve this is to keep a counter and increase it whenever you find an item below the threshold.

Start by creating a variable like count and set it to 0. That variable will store how many low-stock items you have seen so far.

Then go through the quantities one by one. For each quantity, compare it with the threshold.

The condition you care about is:

stock[i] < threshold

If that condition is true, increase count by 1.

After checking the whole list, count is the final answer, so that is what you print.

The logic stays simple because every item is handled the same way: compare, count if needed, and move on.

Best Answers

Solutions Coming Soon

Verified best solutions for this Challenge are still being analyzed and will be available soon.