Practice
Wheelbarrow Restock Tracker
2022/Oct/Nov·Variant 3
MEDIUMLoops
A hardware store uses an algorithm to ensure there are enough wheelbarrows in stock. The initial stock is 10 and total sold starts at 0.
The program takes a sequence of string inputs ("Y" for a sale, "N" to stop). Every time a wheelbarrow is sold ("Y"), the stock drops by 1. If the stock drops below 5, the program outputs "Add new stock" and adds 10 to the stock. When "N" is entered, output the total number sold.
Input: A sequence of "Y" and "N" string inputs, ending with "N". Output: "Add new stock" when stock falls below 5, then the total sold after "N".
Example:
Input: Y Y Y Y Y Y N
Output: Add new stock
6
Premium is coming soon. All grading features are currently unlocked.
Sample Test Cases
Test 1: Triggers one restock
Inputs: Y, Y, Y, Y, Y, Y, N
Expected: Add new stock
6
Test 2: No restock triggered
Inputs: Y, Y, Y, N
Expected: 3
Ctrl+Enter
Press Ctrl+Enter to run your code
or Ctrl+Shift+Enter to grade