Count Tested Devices After Test Operations Problem
Count Tested Devices After Test Operations Problem — ExecCode Easy DSA Practice
Solve the Count Tested Devices After Test Operations problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given a 0-indexed integer array batteryPercentages having length n, denoting the battery percentages of n 0-indexed devices. Your task is to test each device i in order from 0 to n - 1, by performing the following test operations:. If batteryPercentages[i] is greater than 0: Increment the count of tested devices. Decrease the battery percentage of all devices with indices j in the range [i + 1, n - 1] by 1, ensuring their battery percentage never goes below 0, i.e, batteryPercentages[j] = max(0, batteryPercentages[j] - 1). Move to the next device. Return the required answer exactly as shown in the examples.
Examples
Input {"batteryPercentages": [1, 1, 2, 1, 3]}; Output 3. Input {"batteryPercentages": [0, 1, 2]}; Output 2
Constraints
1 <= n == batteryPercentages.length <= 100 0 <= batteryPercentages[i] <= 100
Practice Count Tested Devices After Test Operations free on ExecCode. Browse DSA problems, topic map, and placement guides.