Restock Alert

Easy · rating 1000 · Arrays, Implementation

A warehouse tracks items that need reordering. The first line contains n, the number of items. Each of the next n lines has two integers stock threshold. Print how many items have stock strictly below their threshold.

Constraints: 1 ≤ n ≤ 105

Editorial

Approach

For each item compare its stock to its threshold and count the ones that fall short. A running counter over the lines is all that's needed.

count = 0
for _ in range(n):
    stock, threshold = map(int, input().split())
    if stock < threshold:
        count += 1
print(count)

Watch the boundary

"Strictly below" means an item exactly at its threshold does not need restocking — use <, not .

Complexity

Time: O(n). Space: O(1).

Related problems

Open Restock Alert in Code Arena →