Reconcile a Stock Ledger

Medium ⏱ 12 min 51% acceptance ★★★★★ 4.8
Write final_stock(opening, movements) where movements are (type, qty) tuples with types 'purchase', 'sale', 'return' (customer return: stock comes back), 'damage'. Track the balance; a sale that would drive stock negative is skipped and its index recorded. Return (final_qty, skipped_indexes).

Examples

Example 1
Input
final_stock(10, [('sale', 4), ('sale', 8), ('purchase', 5), ('sale', 8)])
Output
(3, [1])
Explanation

The 8-unit sale at index 1 exceeded stock and was skipped.

Constraints

  • Stock never goes below 0.
  • Skipped sales listed by movement index.

Topics

Business Logicreconciliation

Companies

Tally SolutionsZohoUdaan

Hints

Hint 1

A dict of type → sign keeps the arithmetic clean.

Hint 2

Check before applying sales/damage.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.