Compute a Food Order Bill With Capped Coupons and Distance Slabs
Last updated: November 29, 2026
Quick Overview
Given cart items with price, quantity and packaging charge, an optional coupon (percentage with a cap, or flat, each with a minimum order value), the delivery distance and whether the user is a member, return the full bill breakdown: item total, discount, packaging, GST, delivery fee and grand total.
Swiggy
November 29, 20260
0
0 solved
Given cart items with price, quantity and packaging charge, an optional coupon (percentage with a cap, or flat, each with a minimum order value), the delivery distance and whether the user is a member, return the full bill breakdown: item total, discount, packaging, GST, delivery fee and grand total.
The checkout bill is the screen every Swiggy customer sees, and bugs in it show up as support tickets and refund cost within minutes. A phone screen uses it to check that you clarify business rules before coding, handle money without floating point, and keep the ordering of discount, tax and fees explicit.
What the Interviewer Expects
- Asks which amounts the coupon minimum and the GST apply to before coding
- Represents money as integer paise, not floats
- Applies the percentage cap and never lets a discount exceed the item total
- Handles members getting free delivery only above a threshold
- Rejects addresses outside the serviceable radius cleanly
- Returns a breakdown, not just a total, so the UI can render each line
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you support stacking a bank offer on top of a restaurant coupon?
- Surge pricing during rain adds a variable fee. Where does it go in the calculation and is it taxed?
- How would you make sure the bill shown in the app matches the amount charged at payment time?
- How would you test this function so a rule change cannot silently break existing coupons?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Inputs: items as (price, qty, packaging_per_unit) in paise, an optional coupon dict, distance_km, and is_member. Rules I confirm with the interviewer:
- Coupon eligibility uses the item tota...
High-Level Design
Compute in a fixed order: item total and packaging, then discount, then taxable base, then GST with round-half-up on paise, then delivery fee, then total. Keeping each value in the returned dict lets ...