AI Engineer Problems › Error Handling & Edge Cases

Financial Balance Sheet Identity Checker

Easy · Coding · Error Handling & Edge Cases · Asked at H&R Block, Intuit

Financial Balance Sheet Identity Checker

When extracting key values from balance sheets, numbers are often parsed as strings with mixed formats (e.g., $1,200,000, 500M, 12.5K, or empty/missing values).

Implement a function verify_balance_sheet(assets_str, liabilities_str, equity_str) that:

  1. Normalizes and parses the text inputs into numeric floats. Support suffixes: M/m (Millions), K/k (Thousands), B/b (Billions).
  2. Handles missing/empty/None values by treating them as 0.0.
  3. Verifies if the fundamental accounting identity holds true: $\text{Assets} = \text{Liabilities} + \text{Equity}$
  4. Return a tuple of (is_balanced: bool, discrepancy: float). Round the discrepancy to 2 decimal places.

Example

verify_balance_sheet("$1.2M", "800K", "400,000")
# Returns: (True, 0.0)

Solve it in the browser on GenAIDojo