Code Logo

Calculate Phone Bill

Published at19 Apr 2026
Easy 0 views
Like0

This problem is based on a simple monthly phone bill. A customer already has a base plan fee, but extra minutes add extra cost on top of that.

You are given the base fee, the number of extra minutes, and the cost for each extra minute. Your task is to calculate the final amount to pay.

For example, if the base fee is 20, the extra minutes are 5, and each extra minute costs 2, the answer is 30. That is because the extra part costs 10, and 20 + 10 = 30.

So the task is to calculate the extra charge and add it to the base fee.

Example Input & Output

Example 1
Input
base_fee = 10, extra_minutes = 4, cost_per_minute = 1
Output
14
Explanation

The extra cost is 4, so the total becomes 14.

Example 2
Input
base_fee = 15, extra_minutes = 0, cost_per_minute = 3
Output
15
Explanation

With no extra minutes, the final bill stays the same as the base fee.

Example 3
Input
base_fee = 20, extra_minutes = 5, cost_per_minute = 2
Output
30
Explanation

The extra 5 minutes cost 10, so the final bill becomes 30.

Algorithm Flow

Recommendation Algorithm Flow for Calculate Phone Bill
Recommendation Algorithm Flow for Calculate Phone Bill

Solution Approach

A simple way to solve this is to break the bill into two parts: the base cost and the extra cost.

First, calculate how much the extra minutes cost in total. You can do that by multiplying the extra minute count by the cost per minute.

The formula is:

extra_cost <- extra_minutes * cost_per_minute

After that, add the extra cost to the base fee.

The final update is:

final_bill <- base_fee + extra_cost

Once you have that value, print it as the answer.

The whole idea is straightforward multiplication followed by addition.

Best Answers

Solutions Coming Soon

Verified best solutions for this Challenge are still being analyzed and will be available soon.