Mobile-money tariff lookup
A free easy coding practice problem. Solve it in JavaScript, TypeScript or Python and check your solution against fresh hidden tests — edge cases and random inputs — as often as you like.
- Difficulty
- Easy
- Type
- Function
- Languages
- JavaScript, TypeScript or Python
Problem
A mobile-money tariff is a list of bands [min, max, fee] (inclusive amounts, sorted ascending, non-overlapping, possibly with gaps between them). For each amount in amounts, its fee is the fee of the band containing it, or -1 when no band contains it (the transfer isn't allowed). Return [fees, total]: the fee per amount (in input order) and the total fee collected over the allowed transfers.
Function signature
// JavaScript
function tariffFees(tiers, amounts)
// TypeScript
function tariffFees(tiers: any, amounts: any): any
// Python
def tariff_fees(tiers, amounts):Examples
tariffFees([[1,100,0],[101,500,7],[501,1000,13]], [50,101,1000,1001])→[[0,7,13,-1],20]tariffFees([[10,49,1],[100,199,5]], [10,75,150])→[[1,-1,5],6]
How checking works
Run your code against the examples above, then submit a check: it runs on the server against hidden tests built fresh each time, including edge cases and random inputs. Practice is untimed and never affects a verified score; when you are ready, take a graded coding challenge to earn a badge.