Skip to content
RED SAGSkills
easy15 ptsfintechmath

GST Invoice Totals

A billing service stores every amount as a whole number of cents (paise) to avoid floating-point surprises. An invoice is a list of lines, each { unitPriceCents, quantity, gstPercent }.

For each line, the net amount is unitPriceCents * quantity. The tax for that line is net * gstPercent / 100, rounded to the nearest whole cent, with exact halves rounded up (so 2.5 becomes 3). Tax is rounded per line, not on the invoice total.

Return { netCents, taxCents, grossCents }, where netCents and taxCents are the sums over all lines and grossCents = netCents + taxCents. An empty invoice totals zero.

Example 1

Input: lines = [{"unitPriceCents":1000,"quantity":2,"gstPercent":18}]
Output: {"netCents":2000,"taxCents":360,"grossCents":2360}
Explanation: Net 2000; tax 2000 x 18% = 360.

Example 2

Input: lines = [{"unitPriceCents":999,"quantity":3,"gstPercent":5},{"unitPriceCents":250,"quantity":1,"gstPercent":12}]
Output: {"netCents":3247,"taxCents":180,"grossCents":3427}
Explanation: Line 1 tax 149.85 rounds to 150, line 2 tax is 30.

Constraints

  • 0 <= lines.length <= 10^4
  • 0 <= unitPriceCents <= 10^7
  • 0 <= quantity <= 10^4
  • gstPercent is an integer between 0 and 40
Hint 1

Keep everything in integers: Math.floor((net * gstPercent + 50) / 100) rounds half up.

Hint 2

Round each line before adding it to the total.

Good practice for: Backend Developer, Full Stack Developer, Blockchain Developer, Data Engineer, Automation Test Engineer, Mobile App Developer

Run checks your code on 3 sample tests. Submit runs all 8 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.