Compute Zoho Books Invoice Totals With Discounts And Tax Rounding

Last updated: November 29, 2026

Quick Overview

Given invoice line items with quantity, rate, optional line discount and a tax percentage, plus an optional invoice-level discount, compute the subtotal, discount, tax per tax rate and grand total, rounded to two decimals the way an accounting product must.

Zoho
Coding & Algorithms
Software Engineer
Zoho
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Given invoice line items with quantity, rate, optional line discount and a tax percentage, plus an optional invoice-level discount, compute the subtotal, discount, tax per tax rate and grand total, rounded to two decimals the way an accounting product must.

Zoho Books generates invoices for businesses in many tax regimes, including India's GST with several slab rates, so the totals on a PDF must match what the accountant computes by hand. The interviewer is checking decimal arithmetic instead of floats, a stated rounding policy and the order in which discounts and tax are applied.

What the Interviewer Expects
  • Use Decimal (or integer minor units), never binary floats, for money
  • State and apply a rounding mode such as half-up
  • Apply discounts before tax and explain why
  • Group tax by rate so the invoice shows one line per slab
  • Make the total equal the sum of the displayed components
Key Topics to Cover
Decimal arithmetic
Rounding policy
Tax computation
Financial correctness
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Should tax be rounded per line or per rate group, and what changes if a country requires per-line?
  • How would you support tax-inclusive prices?
  • How do you handle currencies with zero or three minor digits?
  • How would you test this against an accountant's expected output?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Lines: qty, rate, tax_pct, optional line_discount_pct. Invoice discount is a percentage applied to the subtotal before tax. Round each line amount to cents, compute tax on the discounted base ...

High-Level Design

Convert every input through str to Decimal so 0.1 stays exact. Accumulate a taxable base per tax rate. Apply the invoice discount factor to each base before computing its tax, so the tax lines a...


Submit Your Answer
Markdown supported

Related Questions