Ctrl K

Checks Drain the Rest

Easy
Devices stand in a row on a test bench, and charges[i] is the battery level of device i in percent. A technician walks from left to right and, for each device: - if its charge is above zero, the device is checked, and **every device to its right** loses 1 percent of charge (never going below zero); - if its charge is zero, the device is skipped and nothing changes. Return the number of devices that get checked.
Example 1
charges=[2, 1, 3, 0, 2] → 2

Device 0 is checked and the later charges become [0, 2, 0, 1]. Device 1 is skipped, device 2 is checked, leaving [0, 0]. Devices 3 and 4 are empty. Two devices are checked.

Example 2
charges=[0, 5, 5] → 2

Device 0 is empty; devices 1 and 2 are checked, the last one still holding 4 after the first check.

Example 3
charges=[1, 1, 1, 1] → 1

The very first check drains every other device to zero.

Constraints
  • 1 ≤ len(charges) ≤ 100
  • 0 ≤ charges[i] ≤ 100
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPump Rods at Their Peak HardThe Candidate With Most Votes EasyHow Long the Light Stayed On EasyRepack the Tray EasyValues One Apart Easy
loading Python…
Input
charges=[2, 1, 3, 0, 2]
Expected
2

Run checks the first 3 tests in your browser. Submit checks all 110 tests on the server, hidden ones included.