What the shelf is worth
Month-end valuation multiplies what is on each shelf by its unit cost and adds it up.
- Quantity and cost are both in whole units; the answer is in minor currency units.
- Negative quantities are counting errors — skip those rows entirely.
- An empty shelf is worth nothing.
StockValue(rows: list<Row>) → int
C# needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.
Where you start
public int StockValue(List<Row> rows) {
}
Worked examples
| Call | Result |
|---|---|
StockValue(new List<Row> { new Row(3, 250), new Row(2, 100) }) | 950 |
StockValue(new List<Row> { new Row(-4, 500), new Row(1, 500) }) | 500 |
StockValue(new List<Row> { new Row(0, 900) }) | 0 |
StockValue(new List<Row> { }) | 0 |
Hint
One pass, one accumulator, one guard.
Reference solution in C#
public int StockValue(List<Row> rows) {
int total = 0;
foreach (var r in rows) if (r.Qty > 0) total += r.Qty * r.UnitCost;
return total;
}