Skip to content
CodeKruPro

Compute an electricity bill from unit slabs

Coding problemEasyAsked in: Wipro

An electricity company charges by slabs. The first 100 units cost 3 rupees each. Units 101 to 200 cost 5 rupees each. Units 201 to 500 cost 7 rupees each. Every unit above 500 costs 10 rupees.

Given the number of units used, return the bill in rupees. Each unit is charged at the rate of the slab it falls in, so 150 units cost 100 x 3 + 50 x 5 = 550.

Examples

Example 1
Input: units = 150
Output: 550
Example 2
Input: units = 0
Output: 0
Example 3
Input: units = 600
Output: 3900
300 + 500 + 2,100 + 100 x 10.

Constraints

  • units is between 0 and 1,000,000

Run checks the 3 examples. Submit also runs the hidden tests: edge cases, large inputs and a time limit.

Run your code to see the results here.

This question is part of Pro+

Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.

See Pro+

Already have Pro+? Sign in