Problem
Gym Fees Calculator
Learn this problemProblem statement
A gym offers membership plans with the following prices:
3months:50006months:90009months:1200012months:15000
You are given a requested membership length months. Calculate the total cost using the greedy priority order 12, then 9, then 6, then 3. Use as many plans as possible at each priority before moving to the next smaller plan.
If months is not divisible by 3, return "Error". Otherwise, return the total cost as a string.
Function
calculateGymFees(months: int) → StringExamples
Example 1
months = 18return = "24000"Use one 12-month plan and one 6-month plan, for a total cost of 15000 + 9000 = 24000.
Example 2
months = 15return = "20000"Use one 12-month plan and one 3-month plan.
Example 3
months = 10return = "Error"10 is not divisible by 3, so the requested length cannot be represented by the available plans.
Constraints
months >= 1