Code Logo

Count Low Stock Items

Published at19 Apr 2026
Loops & Iteration Easy 7 views
Like0

Given an array of inventory quantities, count how many items have a quantity less than 10 (low stock). Return the number of low-stock items.

For example, quantities [15, 3, 20, 8, 12] has 2 low-stock items (3 and 8). All high stock [100, 50] has 0. All low stock [5, 2, 9] has 3. An empty array returns 0.

Threshold-based counting is used in inventory management (reorder alerts), quality control (defect thresholds), and monitoring systems (alert thresholds). It teaches comparison operators and conditional counting.

The solution initializes a counter, loops through each quantity, and increments when the value is below the threshold. Return the total after the loop.

Edge cases include an empty array (return 0), quantities exactly at the threshold (10 is not low), and negative quantities (which are below any positive threshold).

Learn about our pseudocode specification
Guide

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

Solution Approach

Iterate through the array and count elements less than the threshold of 10.

function countLowStock(items)
  count = 0
  for each q in items
    if q < 10 then count = count + 1
  return count

Initialize count to 0. For each quantity value, check if it is strictly less than 10. If so, increment the counter. After processing all items, return count. Values equal to exactly 10 are not counted as low stock since they meet the minimum threshold.

Time complexity is O(n), space complexity is O(1).

Best Answers

Pseudocode - Approach 1
program count_low_stock_items
dictionary
   stock: array[1..100] of integer
   threshold, count, i, n: integer
algorithm
   input(stock, threshold)
   count <- 0
   n <- stock.length
   for i <- 0 to n - 1 do
      if stock[i] < threshold then
         count <- count + 1
      endif
   endfor
   output(count)
endprogram